May 11, 2024, 04:56:32 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Question on Toolbars in MDIFRAME

Started by RG, October 10, 2009, 09:50:33 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RG

Here's the situation: I have a MDIFRAME parent with two child windows. When I added a toolbar to one of the child windows, everything looks fine when the program starts (toolbar in child, no toolbar in parent) but when the parent is resized or minimized/maximized, suddenly white space for a toolbar shows up in the parent. After I added a different toolbar to the second child window, again everything starts fine but after resizing, the parent now shows white space for two toolbars, double the height of just one. Looks as if the parent is inheriting the children's toolbar space allocation upon resizing (but the parent doesn't show the toolbars, just the white space and the child windows are positioned below the toolbar space). Anyway to turn this off or am I missing some style setting? I've searched the forums and the web but haven't found anything about this.

Thanks, Rich

GWS

Rich,

I haven't the time to look into this, but here is a response by Bevets (Steve) from 2005, answering a similar query.
It may contain a clue for you ..  :)

From the Pyxia Forum:

"Hi all. Back with the old backache.

MDI!

Toolbars!

I have added a toolbar to a browser window plus a toolbar to the MDi window. Everything appears to be ok until I resize the frame, when that happens the frame toobar doubles in size wether I use @tbresize or not

Jeffers

___________________________

Looks like a similar problem, if you remove the toolbar from the child window it doesn't happen.

You may be able to modify Earns code from the above link to work with the toolbar as well.

As for the Status Window another option is to just use the Status Window of the Frame, when a child window is
selected the relevant message could be displayed for the child window.

You could keep each child windows messages in an array for example.
SetControlText frame,2,ChildMessages[1]

Bevets
___________________________________________

Thats ok steve. I already use a different method to send messages to the MDI status bar via WM_SETFOCUS in the child window.

The thing is about subclassing, is that I can see a piece of code is subclassed and I can inccorporate into my code, its just that I dont know the rules about subclassing, therefore its a bit beyond my knowledge at the moment.

However back to plan. I shall make a big toolbar in the main frame and control my browser from there.

Jeff
__________________________________________

Hi Jeff, i've created a MDI Browser example which by the look of your code is what your trying to do.
The code handles the toolbars and status windows using Earns code from other post above.
If the code is saved and executed from the projects directory it will use a toolbar image from there.

Normal disclaimer, not heavily tested and may contain bugs. ;)

Steve
__________________________________________


'http://www.pyxia.com/community/viewtopic.php?p=51690#51690
'an example of how MDI windows can be used with IBASIC
'define the frame Window and a maximum of 20 child windows
'requires IBasic Professional 1.0 or greater
'modified by bevets for Browser windows
Declare "User32.dll",GetWindowLongA(hwnd:Int, nIndex:Int),Int
Declare "User32.dll",SetWindowLongA(hwnd:Int, nIndex:Int, dwNewLong:Int),Int
Declare "User32.dll",SetWindowPos(hwnd:Int, hWndInsertAfter:Int, x:Int, y:Int, cx:Int, cy:Int, wFlags:Int),Int
Declare "User32.dll",CallWindowProcA(lpPrevWndFunc:Int, hwnd:Int, msg:Int, wParam:Int, lParam:Int),Int
Declare "User32.dll",GetSystemMetrics(nIndex:Int),Int
Const SM_CXFRAME = 32
Const SM_CYBORDER = 6
Const SM_CYCAPTION = 4
Const SM_CYFRAME = 33
Const SM_CYMENU = 15
Const SM_CYMENUSIZE = 55
Const GWL_WNDPROC = -4
Const HWND_BOTTOM = 1
Const WM_SIZE = &H5
Const WM_SIZING = &H214
Const WM_SetFocus = 0x7

Def orig:Int

/****************************/
Def urlwin,frame,neww[20],wb[20]:Window
Def run,wndcnt,x,currentchild:Int
Def left,top,width,height,panes[4]:Int
Def stattext:String
'open the frame
OpenWindow frame,0,0,800,600,@MDIFrame|@MinBox|@MaxBox|@Size,0,"MDI Demo",&wndproc
'Use InsertMenu with @MDIFrame windows so we dont erase the standard Menu
BeginInsertMenu frame,0
   MenuTitle "&File"
   MenuItem "&New",0,1
   MenuItem "&Quit",0,2
EndMenu
'add a status bar
Control frame,@Status,"Status",0,0,0,0,0,2
'Get the windows client size and set up 4 panes For the status Window
GetClientSize frame,left,top,width,height
panes = width - 120,width - 80,width - 40,-1
ControlCMD frame,2,@SWSetPanes,4,panes
'set the initial pane text
'stattext = Using("& #### ####","Client size",width,height)
ControlCMD frame,2,@SWSetPaneText,0,stattext
ControlCMD frame,2,@SWSetPaneText,1,"Pane 2"
ControlCMD frame,2,@SWSetPaneText,2,"Pane 3"
ControlCMD frame,2,@SWSetPaneText,3,"Pane 4"
Rem load a toolbar from a bitmap File
Def hbitmap:UINT
Def tbArray[10]:Int
tbArray = 2,3,4,0,5,6,7,0,8,9
hbitmap = LoadImage(GetStartPath + "toolbar.bmp",@IMGBITMAP | @IMGMAPCOLORS)
If LoadToolBar(frame,hbitmap,98,tbArray,10,@TBTOP | @TBFROMHANDLE)
   ControlCMD frame,98,@TBSETLABELS,"New|Open|Save|Cut|Copy|Paste|Print|Help||"
   ControlCMD frame,98,@TBRESIZE
EndIf
/*
'Load a toolbar from a bitmap File
Def hbitmap:UINT
Def tbArray[8]:Int
tbArray = 2,3,4,0,5,0,6,7
hbitmap = LoadImage(102,@imgbitmap)
If LoadToolBar(frame,hbitmap,98,tbArray,8,@TBTRANSPARENT|@tbtop|@tbfromhandle|@TBFLAT|@TBTOOLTIPS)
   ControlCMD frame,98,@TBSETTIP,2,"New Window"
   ControlCMD frame,98,@TBSETTIP,3,"Open Account "
   ControlCMD frame,98,@TBSETTIP,4,"Save As Account"
   'ControlCMD frame,98,@TBSETTIP,5,"Print Document"
   ControlCMD frame,98,@TBSETTIP,6,"Help-Contents"
   ControlCMD frame,98,@TBSETTIP,7,"Go Web"
   ControlCMD frame,98,@TBSETBUTTONSIZE, 26, 26
   ControlCMD  frame,98,@TBSETBITMAPSIZE, 24, 23
   ControlCMD frame,98,@tbresize   
EndIf
*/
run = 1
wndcnt = 0
'process messages Until someone closes us
WaitUntil run = 0
CloseWindow frame
If hbitmap <> NULL Then DeleteImage hbitmap,@IMGBITMAP
End
'our Window subroutine For the frame and child windows
Sub wndproc
Select @Class
   Case @IDCloseWindow
      If #<Window>@HitWindow = frame
         SetWindowLongA(frame.hwnd,GWL_WNDPROC,orig)
         run = 0
      Else
         CloseWindow #<Window>@HitWindow
      EndIf
   Case @IDControl
      Select @ControlID
         Case 2
            OpenNewWindow()
      EndSelect
   Case @IDMenuPick
      Select @MenuNum
         Case 1
            OpenNewWindow()
         Case 2
            run = 0
      EndSelect
   Case @IDSize
      'resize the status Window and update the panes
      'check To make sure the status Window exists
      'it may Not have been added To the Window yet.
      If ControlExists(frame,2)
         'Tell the status Window we are sizing
         ControlCMD frame,2,@SWResize
         'Get the client size of the Window and
         'display it in the status bar
         'calculate the right edges of the other panes.
         GetClientSize frame,left,top,width,height
         panes = width - 120,width - 80,width - 40,-1
         ControlCMD frame,2,@SWSetPanes,4,panes
         'stattext = Using("& #### ####","Client size",width,height)
         ControlCMD frame,2,@SWSetPaneText,0,stattext
      EndIf
      'resize the toolbar
      If ControlExists(frame,98)
         ControlCMD frame,98,@TBRESIZE
      EndIf
   Case @IDCreate
      If #<Window>@HitWindow=frame
         orig=GetWindowLongA(frame.hwnd,GWL_WNDPROC) :'need the handle To the current wndproc For passthru messages
         SetWindowLongA(frame.hwnd,GWL_WNDPROC,&ClientSubClass) :'set the wndproc handler To my process
      EndIf
EndSelect
Return
EndSub
Sub OpenNewWindow
   Def x,y,w,h:Int
   wndcnt = -1
   For x=0 To 19
      If neww[x] = 0
         wndcnt = x
         currentchild=x
         BreakFor
      EndIf
   Next x   
   If wndcnt > -1
      name$ = "Browser"+LTrim$(Str$(wndcnt+1))
      OpenWindow neww[wndcnt],@UseDefault,0,0,0,@Size|@MinBox|@MaxBox,frame,name$,&chdproc
      'Browser controls 
      Control neww[wndcnt],@SysButton,"GO",743,42,46,20,@CTLBTNDefault,1
      Control neww[wndcnt],@Edit,"",2,40,735,23,0x50800000|@CTEditAutoH,2
      Control neww[wndcnt],@Status,"Status",0,0,0,0,0,40
      If LoadToolBar(neww[wndcnt],hbitmap,98,tbArray,10,@TBTOP | @TBFROMHANDLE)
         ControlCMD neww[wndcnt],98,@TBSETLABELS,"New|Open|Save|Cut|Copy|Paste|Print|Help||"
         ControlCMD neww[wndcnt],98,@TBRESIZE
      EndIf
      OpenWindow wb[wndcnt],2,65,600,400,@NoAutoDraw|@NoCaption,neww[wndcnt],"Web Browser",&webmain
      If AttachBrowser(wb[wndcnt])<>0
         MessageBox neww[wndcnt],"Unable To create embedded browser","error"
         CloseWindow wb[wndcnt]
         CloseWindow neww[wndcnt]
         Return
      EndIf
      SendMessage neww[wndcnt],@IDSize,0,0
      BrowseCMD wb[wndcnt],@Navigate,"http://www.pyxia.com"
   EndIf
Return
EndSub
Sub chdproc
   Def x,y,w,h:Int
   Select @Class
      Case WM_SetFocus
         For x=0 To 19
            If neww[x] = #<Window>@HitWindow
               currentchild=x
               BreakFor
            EndIf
         Next x
      Case @IDControl
         Select @ControlID
            Case 1:'Go
               BrowseCMD wb[currentchild], @Navigate,GetControlText neww[currentchild],2
            Case 3:'Backward
           
            Case 4:'Forward
           
            Case 5:'Stop
           
            Case 6:'Refresh
           
            Case 7:'Home
           
            Case 8:'Print
           
            Case 9:'Add BookMark
         EndSelect   
      Case @IDCloseWindow
         CloseWindow #<Window>@HitWindow
      Case @IDSize
         ControlCMD #<Window>@HitWindow,98,@TBRESIZE
         ControlCMD #<Window>@HitWindow,40,@SWResize
         ControlCMD neww[currentchild],40,@SWResize
         ControlCMD neww[currentchild],500,@tbresize
         GetClientSize(neww[currentchild],x,y,w,h) 
         'here we test For the browser Window To make 
         'sure it has been created before we try To size it. 
         If (wb[currentchild] <> 0) 
            x = 2 
            y = 65 
            h = h -85 
            w = w-2 
            SetSize(wb[currentchild],x,y,w,h)
            SetSize(neww[currentchild],w-14,h+68,15,16,11)
            SetSize(neww[currentchild],x,h+68,w-18,23,10)
            SetSize(neww[currentchild],x,40,w-55,23,2)
            SetSize(neww[currentchild],w-47,43,46,20,1)
         EndIf
   EndSelect
Return
EndSub
Sub webmain
   Def strStatus[500] As IString
   Select @Class 
      Case @IDBeforeNav
         BrowseCMD(wb[currentchild],@GetNavURL,strStatus,500)
         SetControlText neww[currentchild],2,strStatus
      Case @IDNavComplete 
      Case @IDSTATUSTEXTUPDATE
         BrowseCMD wb[currentchild], @GETSTATUSTEXT, strStatus, 500
         SetControlText neww[currentchild],40,strStatus
   EndSelect 
Return 
EndSub
Sub ClientSubClass(hwnd:Int,uMsg:Int,wParam:Int,lParam:Pointer),Int
Def l,t,w,h,hs,ht:Int
Select uMsg
   Case  WM_SIZE
   Case& WM_SIZING
      GetSize frame,l,t,w,ht,2
      GetSize frame,l,t,w,hs,98
      GetSize frame,l,t,w,h
      h-= ht
      h-= hs
      h-= GetSystemMetrics(SM_CYMENU)
      h-= GetSystemMetrics(SM_CYBORDER)
      h-= GetSystemMetrics(SM_CYCAPTION)
      h-= GetSystemMetrics(SM_CYFRAME)*2
      w-= GetSystemMetrics(SM_CXFRAME)*2
      setwindowpos(frame.hClient,HWND_BOTTOM,0,hs,w,h,0)
      ControlCMD frame,2,@SWResize
      ControlCMD frame,98,@tbresize
   Return 0
EndSelect
Return CallWindowProcA(orig,hwnd,uMsg,wParam,lParam)
EndSub



Hope it helps ..

best wishes, :)

Graham
Tomorrow may be too late ..

RG

Thanks Graham! This looks like the very same issue - the frame somehow allocates toolbar space to itself upon resizing when a child has a toolbar. I'll have to dig into the code to see if I understand what Steve did. This is at least a start.

Rich

RG

Haven't been able to make any improvements. If you don't add the toolbar to the frame in this example, you get that same behavior of a white strip showing up in the frame upon resizing. I tried using resizing commands which worked on the toolbars themselves but not the white area in the frame (since I didn't add a toolbar to the frame, there's no control number to reference and the control numbers from the children don't have any obvious effect). Hmmm, I'm stumped. I may have to give up on toolbars or recreate the effect of a MDI frame using normal windows.

Rich

Ionic Wind Support Team

Rich,
Toolbars in Emergence are specifically designed for top level windows, not child windows.  That is not to say it can't be done, you would need to subclass the the MDI frame to prevent it from resizing the client window when it receives a WM_SIZE message, in other words you would just call DefFrameProcA in response to WM_SIZE and not call the frames handler.

Not much different than subclassing a control, which there are many examples on the forums.

Paul.
Ionic Wind Support Team

RG

Thanks Paul for the perspective. Turns out if I simply remove the @MDIFRAME but leave the two windows as children of the main, it works as I need. Separate toolbars for each child and no toolbar area added to the parent when it's resized.

Rich