a "how am i doing" test version of dockwindow

Share your advanced PureBasic knowledge/code with the community.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

a "how am i doing" test version of dockwindow

Post by localmotion34 »

Code updated for 5.20+

i am releasing the source i have so far in a little test so people can check it out to see if it is worth pursuing. just copy tyhe code and give it a run. let me know what you really think, or if you have any suggestions.

Code: Select all

Structure dockwindow
  parentwhandle.l
  x.l
  y.l
  Width.l
  Height.l
  Caption.s
EndStructure

Procedure createdockwindow(parenthandle,x,y,Width,Height,Title$); Create a window in a "Docked" state
  hwnd=WindowID(OpenWindow( #PB_Any,  x,y,Width,Height,Title$ ,#PB_Window_Invisible))
  SetWindowLong_( hwnd,#GWL_STYLE, #WS_CHILD|#WS_DLGFRAME|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
  SetWindowPos_( hwnd,0,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE|#SWP_FRAMECHANGED )
  SetParent_( hwnd, parenthandle )
  MoveWindow_(hwnd,x,y,Width,Height, #True )
  ShowWindow_(hwnd, #SW_SHOW)
  ProcedureReturn hwnd
EndProcedure

Procedure dockwindow(dockhandle,parenthandle,x,y,Width,Height);Docks Your Window and Makes it Immobile
  RedrawWindow_(dockhandle,0,0,7)
  SetWindowPos_( hwnd,0,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE|#SWP_FRAMECHANGED ) 
  SetParent_(dockhandle,parenthandle)
  SetWindowLong_( dockhandle,#GWL_STYLE, #WS_CHILD|#WS_DLGFRAME|#WS_EX_CLIENTEDGE|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
  ShowWindow_(dockhandle,#SW_SHOW)
  MoveWindow_(dockhandle,x,y,Width,Height, #True )
EndProcedure

Procedure closedockwindow(dockhandle); Close a Dockwindow
  DestroyWindow_(dockhandle)
EndProcedure

Procedure undockwindow(dockhandle,x,y,Width,Height);Undocks Your Window and Makes it a Free Toolwindow
  ShowWindow_(dockhandle,#SW_HIDE)
  SetWindowLong_(dockhandle,#GWL_STYLE,#WS_BORDER|#WS_CAPTION|#WS_DLGFRAME|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
  SetWindowLong_(dockhandle,#GWL_EXSTYLE,GetWindowLong_(dockhandle,#GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
  RedrawWindow_(dockhandle,0,0,7)
  MoveWindow_(dockhandle,x,y,Width,Height, #True )
  RedrawWindow_(dockhandle,0,0,7)
  SetParent_(dockhandle,#Null)
  ShowWindow_(dockhandle,#SW_SHOW)
EndProcedure

Procedure undockToMDI(dockhandle,MDIGadget,newMDIx,newMDIy,newMDIWidth,newMDIHeight);Undocks Your Window and sets its parent to a local MDIgadget
  ShowWindow_(dockhandle,#SW_HIDE)
  ;leftoffset=GetSystemMetrics_(#SM_CXMIN)
  SetWindowLong_(dockhandle,#GWL_STYLE,#WS_BORDER|#WS_CAPTION|#WS_DLGFRAME|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
  SetWindowLong_(dockhandle,#GWL_EXSTYLE,GetWindowLong_(dockhandle,#GWL_EXSTYLE) | #WS_EX_TOOLWINDOW)
  MoveWindow_(dockhandle,0,0,WindowWidth(0),newMDIHeight-5, #True )
  ResizeGadget(MDIGadget,newMDIx,newMDIy,newMDIWidth, newMDIHeight)
  SetParent_(dockhandle,GadgetID(MDIGadget))
  RedrawWindow_(dockhandle,0,0,7)
  ShowWindow_(dockhandle,#SW_SHOW)
EndProcedure

Procedure getDockstate(dockhandle);returns a dockwindow state: 0 if undocked, 1 if docked
  State=GetWindowLong_(dockhandle,#GWL_STYLE)
  If State =381681664
    dockstate=0
  Else
    dockstate=1
  EndIf
  ProcedureReturn dockstate
EndProcedure

#GADGET_MDI=0
#MENU=0
Enumeration
  #MENU_Dock
  #MENU_unDock
  #MENU_undocktoMDI
  #get_state
EndEnumeration
wind=OpenWindow(0, 0, 0, 800, 600, "MDI ImageViewer/Docked ToolWindow", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
If CreateMenu(#MENU, WindowID(0))
  MenuTitle("File")
  MenuItem(#MENU_Dock, "Dock Window")
  MenuItem(#MENU_unDock, "UnDock Window")
  MenuItem(#MENU_undocktoMDI, "Undock to MDI")
  MenuItem(#get_state, "Get Dock State")
EndIf
MDIGadget(#GADGET_MDI, 110, 30, WindowWidth(0)-110, WindowHeight(0), 0, 0 )

Quit = 0
x1 = GadgetX(#GADGET_MDI)
dockheight=GadgetHeight(#GADGET_MDI)
Dock1=createdockwindow(wind,0,30,x1,dockheight,"hi")

ListViewGadget(3,0,30,100,510)

Repeat
  Event = WaitWindowEvent()
  
  Select  Event
    Case #PB_Event_CloseWindow
      Quit = 1   
      
    Case  #PB_Event_Menu
      Select EventMenu()
          
        Case #MENU_Dock
          ResizeGadget(#GADGET_MDI,100,30,700, 500)
          x1 = GadgetX(#GADGET_MDI)
          dockheight=GadgetHeight(#GADGET_MDI)
          dockwindow(Dock1,wind,0,30,x1,dockheight)
        Case #MENU_undocktoMDI
          undockToMDI(Dock1,#GADGET_MDI,0,30,800,500)
        Case #MENU_unDock
          undockwindow(Dock1,0,30,100,500)
          ResizeGadget(#GADGET_MDI,100,30,700, 500)
        Case #get_state
          If getDockstate(Dock1)=0
            MessageRequester("","Your Window is undocked")
          Else
            MessageRequester("","Your Window is docked")
          EndIf
          
      EndSelect
    Case #PB_Event_Gadget
      event1=EventGadget()
      Select event1
          
      EndSelect
  EndSelect
  
Until Quit = 1 
also, if you know a way that when a user hold the L button down on a window in a "docked" state, if i can get a rectangle (box) to be drawn around the dockwindow and dragged along with the mouse. then, if the mouse reaches a certain distance away from the dockwindow, it automatically undocks.

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

Looks to work just fine. Two little problems: if you undock to mdi and dock/undock again, titlebar disappears. Also, if you undock to mdi, when you try to move the window, it "jumps" down until you release the mouse. Seems to be a problem with mouse/client coordinates. Maybe handling WM_MOVE?

Regards,
El_Choni
Post Reply