Barre d'outil flotante et ancrable

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Patrick88
Messages : 1564
Inscription : mer. 21/janv./2004 18:24

Barre d'outil flotante et ancrable

Message par Patrick88 »

en fouinant j'ai trouvé ce code, on est encore loin des barres d'outils flottantes de ms-office...

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
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Message par nico »

J'arrive à rien faire, impossible de déplacer quoi que ce soit avec la souris.
Patrick88
Messages : 1564
Inscription : mer. 21/janv./2004 18:24

Message par Patrick88 »

ouais c'est pas top... ça marche avec les options du menu, mais impossible de faire quoi que ce soit avec la souris...

y'a un gars sur le forum anglais qui a fait une lib sensass. mais il ne propose rien en téléchargement, c'est plutot un truc payant....

bon, va falloir que je bidouille un truc, je pense partir d'un containerGadget, et des qu'il y a un glisser/deplacer dessus le transformer en fenetre....

pat
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Message par nico »

Ah ouais, on est-ce qu'on peut essayer ça!
Patrick88
Messages : 1564
Inscription : mer. 21/janv./2004 18:24

Message par Patrick88 »

trouvé sur le forum allemand :

reste à gérer le flottement et l'ancrage des barres...

Code : Tout sélectionner

; Rebar Control by Sparkie 07/22/2004 
; http://www.purebasic.fr/german/viewtopic.php?t=7306&highlight=rebar

#TB_GETBUTTONSIZE = #WM_USER + 58 

Structure myINITCOMMONCONTROLSEX 
dwSize.l 
dwICC.l 
EndStructure 

Procedure.l CreateRebar(hwndOwner, hwndST, hwndTB, hwndCB) 
  rbi.REBARINFO 
  rbBand.REBARBANDINFO 
  rc.RECT 
  icex.myINITCOMMONCONTROLSEX 
    
  icex\dwSize = SizeOf(myINITCOMMONCONTROLSEX) 
  icex\dwICC  = #ICC_COOL_CLASSES | #ICC_BAR_CLASSES 

  InitCommonControlsEx_(@icex) 

  hwndRB = CreateWindowEx_(#WS_EX_TOOLWINDOW, "ReBarWindow32", #Null, #WS_CHILD | #WS_VISIBLE | #WS_CLIPSIBLINGS | #WS_CLIPCHILDREN | #RBS_VARHEIGHT | #CCS_NODIVIDER, 0, 0, 0, 0, hwndOwner, #Null,  GetModuleHandle_(0), #Null) 
  rbi\cbSize = SizeOf(REBARINFO) 
  rbi\fMask  = 0 
  rbi\himl = #Null 
  SendMessage_(hwndRB, #RB_SETBARINFO, 0, @rbi) 
  rbBand\cbSize = SizeOf(REBARBANDINFO) 
  rbBand\fMask  = #RBBIM_COLORS | #RBBIM_TEXT | #RBBIM_STYLE | #RBBIM_CHILD  | #RBBIM_CHILDSIZE | #RBBIM_SIZE; 
  rbBand\fStyle = #RBBS_CHILDEDGE 
;/ turn off XP Skin support to see your color choices in the Rebar here 
  rbBand\clrBack = RGB(200, 200, 128) 
  rbBand\clrFore = RGB(64, 100, 0) 

;/ Set values for band with the StringGadget 
  GetWindowRect_(hwndST, @rc) 
  sttext$ = "String" 
  rbBand\lpText = @sttext$                  ; text to display for StringGadget 
  rbBand\hwndChild = hwndST                 ; handle to our STringGadget 
  rbBand\cxMinChild = 100                   ; min width of band (0 hides gadget) 
  rbBand\cyMinChild = rc\bottom - rc\top    ; min height of band 
  rbBand\cx = 200                           ; width of band 
          
;/ Add the band with the StringGadget 
  SendMessage_(hwndRB, #RB_INSERTBAND, -1, @rbBand) 
        
;/ Get the height of the ToolBar we created earlier 
  dwBtnSize = SendMessage_(hwndTB, #TB_GETBUTTONSIZE, 0,0) 
          
;/ Set values for band with the ToolBar 
  tbtext$ = "ToolBar" 
  rbBand\lpText = @tbtext$                  ; text to display for ToolBar 
  rbBand\hwndChild = hwndTB                 ; handle to our ToolBar 
  rbBand\cxMinChild = 100                   ; min width of band (0 hides ToolBar) 
  rbBand\cyMinChild = dwBtnSize>>16         ; min height of band set to button height 
  rbBand\cx = 200                           ; width of band 
          
;/ Add the band that has the toolbar. 
  SendMessage_(hwndRB, #RB_INSERTBAND, -1, @rbBand); 

;/ Set values for the band with the ComboBox 
  GetWindowRect_(hwndCB, @rc); 
  cbtext$ = "ComboBox" 
  rbBand\lpText = @cbtext$                  ; text to display for ToolBar 
  rbBand\hwndChild = hwndCB                 ; handle to our ComboBOxGadget 
  rbBand\cxMinChild = 100                   ; min width of band (0 hides ComboBox) 
  rbBand\cyMinChild = rc\bottom - rc\top    ; min height of band 
  rbBand\cx = 300                           ; width of band 
          
;/ Add the band that has the combobox 
  SendMessage_(hwndRB, #RB_INSERTBAND, -1, @rbBand); 

  ProcedureReturn hwndRB; 
EndProcedure 
        
If OpenWindow(0, 50, 50, 700, 200, "Rebar Control", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget) 
  If CreateGadgetList(WindowID(0)) 
    hStGad = StringGadget(0, 10, 50, 150, 20, "Hello World") 
    hTbGad = CreateToolBar(0, WindowID(0)); 
    ToolBarStandardButton(0, #PB_ToolBarIcon_New) 
    ToolBarStandardButton(1, #PB_ToolBarIcon_Open) 
    ToolBarStandardButton(2, #PB_ToolBarIcon_Save) 
    SetWindowLong_(hTbGad, #GWL_EXSTYLE, 128)       ; best I can do for now 
    SetWindowLong_(hTbGad, #GWL_STYLE, 1442879821)  ; best I can do for now 
    hCbGad = ComboBoxGadget(1, 10, 100, 100, 200) 
      For a=1 To 5 
        AddGadgetItem(1, -1, "ComboBox item " + Str(a)) 
      Next 
    SetGadgetState(1,0) 
    TextGadget(2, 200, 100, 400, 20, "Clicking on any of the text labels in the Rebar also resizes the band.") 
    TextGadget(3, 200, 130, 400, 20, "Click and drag on any of the text labels to reposition the bands.") 
    CreateRebar(WindowID(0), hStGad, hTbGad, hCbGad) 
  EndIf 
EndIf 
      
Repeat 
          
  Event = WaitWindowEvent() 
  
    Select Event 
      
      Case #PB_Event_Menu 
        
        If Event = #PB_Event_Menu 
          SetGadgetText(0, "ToolBar ID: " + Str(EventMenu())) 
        EndIf 
      
      Case #PB_Event_Gadget 
        
        If EventGadget() = 1 
          SetGadgetText(0, GetGadgetText(1)) 
        EndIf 
        
        
      Case #PB_Event_CloseWindow 
        Quit = #True 
              
    EndSelect 
          
Until Quit = #True 
        
End 
Répondre