Pages

Monday, June 27, 2011

Creating MDI Window with Background in Powerbuilder

MDI Window is a type of window that have capabilities to have a menu inside, microhelp bar, Child window inside, etc. Unfortunally, it can't be have an image background capability, at least in Powerbuilder programming. MDI is standing for Multiple Document Interface.


Here the trick how to put an image as a background in MDI window, with Powerbuilder programming.

*. Create a child window called: w_bkg and put Picture Object named p_1 and set the picture file inside

*. Declare instance integer variables on w_main
1:  Integer ii_wbkg_w  
2:  Integer ii_wbkg_h  


*. Put this below code at open event of w_main
1:  OpenSheet(w_bkg, w_main)  
2:    
3:  ii_wbkg_w = w_bkg.width  
4:  ii_wbkg_h = w_bkg.height  
5:    
6:  triggerevent("ue_mdi_move")  


*. Put this below code at resize event of w_main
1:  TriggerEvent("ue_mdi_move")  


*. Create a new user event, called ue_mdi_move, and put the code below
1:  integer wx,wy,wh,ww  
2:       
3:  // Get current MDI workspace  
4:  wx=this.workspacex ( )  
5:  wy=this.workspacey ( )  
6:  wh=this.workspaceheight ( )  
7:  ww=this.workspacewidth ( )  
8:       
9:  // Set background image  
10:  If ( handle (w_bkg) > 0 ) then  
11:       wh -= 200    // Approx Microhelp Height??   
12:       w_bkg.width=3662  
13:       w_bkg.height=2400  
14:       If ww>w_bkg.width Then  
15:            ww = Integer((ww - w_bkg.width) / 2)   
16:       Else   
17:            ww = 1  
18:       End If  
19:       If wh>w_bkg.height Then  
20:            wh = Integer((wh - w_bkg.height) / 2)  
21:       Else   
22:            wh = 1  
23:       End If  
24:       Move(w_bkg, ww, wh)  
25:  End If  
26:       
27:  // Be sure focus is on us and not the background image   
28:  SetFocus(this)  



Last step, try to run the code, and see the result below

4 comments :

  1. Nice post. I like your blog about Powerbuilder. I have a similar site for developing a tutorial for PB. I see you've already linked it here. I've also included your sites link on mine.

    Happy blogging!

    Sam

    ReplyDelete
  2. Hi Sam, thanks for visiting my blog. Yes, I already included your site on my blog :)
    I hope we can exchange the knowledge about Powerbuilder in the future :)

    ReplyDelete
  3. I cant get it...Is there any changes in above scrip ? When my MDI opens it send error message
    for the open event of MDI fram
    OpenSheet(w_bkg, w_main)
    (Null object reference)

    Pl. suggest what to do

    ReplyDelete
  4. Niraj

    Sorry my mistake, first step, create a child window and save as W_bkg instead of B_bkg. Sorry, I typo the name of the child windows :)

    Should be run smoothly now.

    ReplyDelete