c'est un code posté par Localmotion34 et modifié par Dagcrack...
http://www.purebasic.fr/english/viewtop ... olbar+dock
il faut la lib ToolBarPRO de Danilo, à télécharger là (entres autres) :
http://pbosl.purearea.net/index.php?site=Libs
ça marche en pb 3.94...
Code : Tout sélectionner
#dockleft=4444444440
#dockright=444444441
#docktop=444444442
#dockbottom=444444443
Structure dock
dockx.l
docky.l
Width.l
Height.l
parenthandle.l
dockhandle.l
EndStructure
;Global Dock.TB_GadgetVT
Structure dockwindow
parentwhandle.l
x.l
y.l
Width.l
Height.l
Caption.s
EndStructure
ProcedureDLL createdockwindow(parenthandle,x,y,Width,Height,Title$); Create a window in a "Docked" state
hwnd=WindowID(OpenWindow( #PB_Any,x,y,Width,Height,#PB_Window_Invisible,Title$ ))
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
ProcedureDLL setdockedvalues(dockhandle,*dockhandle.dock,x,y,Width,Height)
*dockhandle\dockx=x
*dockhandle\docky=y
*dockhandle\Width=Width
*dockhandle\Height=Height
*dockhandle\dockhandle=dockhandle
*dockhandle\parenthandle=GetParent_(dockhandle)
EndProcedure
ProcedureDLL 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
ProcedureDLL undockToMDI(dockhandle,MDIGadget,newMDIx,newMDIy,newMDIWidth,newMDIHeight);Undocks Your Window and sets its parent to a local MDIgadget
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)
SetWindowPos_( dockhandle,0,0,0,0,0,#SWP_NOSIZE)
ResizeGadget(MDIGadget,newMDIx,newMDIy,newMDIWidth, newMDIHeight)
SetParent_(dockhandle,GadgetID(MDIGadget))
RedrawWindow_(dockhandle,0,0,7)
ShowWindow_(dockhandle,#SW_SHOW)
EndProcedure
ProcedureDLL 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
ProcedureDLL 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
ProcedureDLL QuickUndock(dockhandle,MDIGadget,Position);Undocks your window to an MDIgadget and automatically resizes the MDI to dimensions +/- the dockwindow
GetWindowRect_(dockhandle,win.RECT) ; Get Dock's dimensions.
dockx=win\left : docky=win\top ; Get X and Y positions of Dock.
dockwidth=win\right-win\left : dockheight=win\bottom-win\top ; Get width and height.
MDIx=GadgetX(MDIGadget)
MDIy=GadgetY(MDIGadget)
MDIWidth=GadgetWidth(MDIGadget)
MDIHeight=GadgetHeight(MDIGadget)
If getDockstate(dockhandle)=1
If Position=#dockleft ;left side
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)
SetWindowPos_( dockhandle,0,0,0,0,0,#SWP_NOSIZE)
ResizeGadget(MDIGadget,MDIx-dockwidth,MDIy,MDIWidth+dockwidth, MDIHeight)
SetParent_(dockhandle,GadgetID(MDIGadget))
RedrawWindow_(dockhandle,0,0,7)
ShowWindow_(dockhandle,#SW_SHOW)
ElseIf Position=#dockright ;right side
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)
SetWindowPos_( dockhandle,0,0,0,0,0,#SWP_NOSIZE)
ResizeGadget(MDIGadget,MDIx,MDIy,MDIWidth+dockwidth, MDIHeight)
SetParent_(dockhandle,GadgetID(MDIGadget))
RedrawWindow_(dockhandle,0,0,7)
ShowWindow_(dockhandle,#SW_SHOW)
ElseIf Position=#docktop ;Top side
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)
SetWindowPos_( dockhandle,0,0,0,0,0,#SWP_NOSIZE)
ResizeGadget(MDIGadget,MDIx,MDIy-dockheight,MDIWidth, MDIHeight+dockheight)
SetParent_(dockhandle,GadgetID(MDIGadget))
RedrawWindow_(dockhandle,0,0,7)
ShowWindow_(dockhandle,#SW_SHOW)
ElseIf Position=#dockbottom ;Bottom side
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)
SetWindowPos_( dockhandle,0,0,0,0,0,#SWP_NOSIZE)
ResizeGadget(MDIGadget,MDIx,MDIy,MDIWidth, MDIHeight+dockheight)
SetParent_(dockhandle,GadgetID(MDIGadget))
RedrawWindow_(dockhandle,0,0,7)
ShowWindow_(dockhandle,#SW_SHOW)
EndIf
EndIf
EndProcedure
ProcedureDLL QuickDock(*dockhandle.dock,MDIGadget,Position);Docks your window with no resize or other changes
RedrawWindow_(*dockhandle\dockhandle,0,0,7)
SetWindowPos_( *dockhandle\dockhandle,0,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE|#SWP_FRAMECHANGED )
SetParent_(*dockhandle\dockhandle,*dockhandle\parenthandle)
SetWindowLong_( *dockhandle\dockhandle,#GWL_STYLE, #WS_CHILD|#WS_DLGFRAME|#WS_EX_CLIENTEDGE|#WS_CLIPCHILDREN|#WS_CLIPSIBLINGS )
ShowWindow_(*dockhandle\dockhandle,#SW_SHOW)
MoveWindow_(*dockhandle\dockhandle,*dockhandle\dockx,*dockhandle\docky,*dockhandle\Width,*dockhandle\Height, #True )
EndProcedure
#MENU=0
Enumeration
#GADGET_MDI
#Frame3D_0
#Radio_0
#Radio_1
#Combo_0
#Panel_0
EndEnumeration
Enumeration
#MENU_Dock
#MENU_unDock
#MENU_undocktoMDI
#get_state
#quick_undock
#quick_dock
EndEnumeration
parentwnd.RECT
Procedure DefineDockPane(dockwindow,*RECTstructure.RECT,x,y,Width,Height)
parent=GetParent_(dockwindow)
GetWindowRect_(parent,parentwnd.RECT)
*RECTstructure\left=parentwnd\left + x
*RECTstructure\top= parentwnd\top + y
*RECTstructure\bottom=*RECTstructure\top+Height +parentwnd\top
*RECTstructure\right=Width +parentwnd\left
EndProcedure
Declare MyWindowCallback(WindowID,message,wParam,lParam)
;-Setup our main window
wind=OpenWindow(0, 0, 0, 800, 600, #PB_Window_ScreenCentered|#PB_Window_SystemMenu, "Docked ToolWindow")
If CreateMenu(#MENU, WindowID())
MenuTitle("File")
MenuItem(#MENU_Dock, "Dock Window")
MenuItem(#MENU_unDock, "UnDock Window")
MenuItem(#MENU_undocktoMDI, "Undock to MDI")
MenuItem(#get_state, "Get Dock State")
MenuItem(#quick_undock,"Quick Undock")
MenuItem(#quick_dock,"Quick Dock")
EndIf
If CreateGadgetList(WindowID())
MDIGadget(#GADGET_MDI, 110, 30, WindowWidth()-110, 560, 0, 0 )
CloseGadgetList()
EndIf
;-setup dockwindow 1
Dock.dock ;here we define the structure associated with the 1st dockwindow
Quit = 0
x1 = GadgetX(#GADGET_MDI)
dockheight=GadgetHeight(#GADGET_MDI)-2
Dock1=createdockwindow(wind,0,30,x1,dockheight,"hi");create dockwindow 1
SetActiveWindow_(Dock1)
SetWindowCallback(@MyWindowCallback())
setdockedvalues(Dock1,@Dock.dock,0,30,x1,dockheight);here we fill the structure of dockwindow 1
CreateGadgetList(Dock1)
ListViewGadget(9,5,10,90,510)
slam.RECT
DefineDockPane(Dock1, @slam.RECT,0,0,10,dockheight)
;-setup dockwindow 2
Dock2=createdockwindow(wind,0,0,800,30,"hi");create a 2nd dockwindow, maybe a REBAR????
hTB = CreateTB( 1 , Dock2, 40, 0, #TBpro_flat );add a toolbar (Danilo's)
AddTBtextButton(100,"Button 01",#TBpro_Button )
AddTBtextButton(101,"Button 02",#TBpro_Button )
AddTBtextButton(102,"Button 03",#TBpro_Button )
AddTBtextButton(103,"Button 04",#TBpro_Button )
hGadget=ComboBoxGadget(34,0,0,100,150)
AddTBgadget( hGadget, 250, 3 )
;-Event Loop
Repeat
Event = WaitWindowEvent()
Select Event
Case #WM_LBUTTONDOWN
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Menu
Select EventMenuID()
Case #MENU_Dock
ResizeGadget(#GADGET_MDI,110,30,700, 560)
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,560)
Case #MENU_unDock
undockwindow(Dock1,0,30,110,560)
ResizeGadget(#GADGET_MDI,0,30,800, 500)
Case #get_state
If getDockstate(Dock1)=0
MessageRequester("","Your Window is undocked")
Else
MessageRequester("","Your Window is docked")
EndIf
Case #quick_undock
QuickUndock(Dock1,#GADGET_MDI,#dockleft)
Case #quick_dock
QuickDock(@Dock.dock,#GADGET_MDI,#dockright)
ResizeGadget(#GADGET_MDI,110,30,700, 560)
Case 100
EndSelect
Case #PB_Event_Gadget
event1=EventGadgetID()
Select event1
EndSelect
EndSelect
Until Quit = 1
Procedure MyWindowCallback(WindowID,message,wParam,lParam)
Shared Dock1
Shared slam.RECT
Shared Dock.dock
Shared possibledock
Shared move.RECT
Shared docknow
Result=#PB_ProcessPureBasicEvents
If WindowID=Dock1
Select message
Case #WM_MOVING ; Main window is moving!
possibledock=1
Case #WM_MOVE
move.RECT
GetWindowRect_(Dock1,move.RECT)
If move\left < slam\right
docknow=1
EndIf
If getDockstate(Dock1)=0 And docknow=0
QuickDock(@Dock.dock,#GADGET_MDI,#dockleft)
ResizeGadget(#GADGET_MDI,110,30,700, 560)
EndIf
EndSelect
EndIf
ProcedureReturn Result
EndProcedure