Page 1 sur 1

Petit exemple, comme ça, pour rien

Publié : mar. 11/oct./2005 11:03
par Chris
Testé sur Win XP

Code : Tout sélectionner

 ;-Constantes Fenêtres
Enumeration
  #Window_0
EndEnumeration

;-Constantes Gadgets
Enumeration
  #MainCont
  
  #Rebar
  
  #Cont_1
  #Btn_1
  #List_1
  #Cmb_1
  
  #Cont_2
  #Explorer
  #Btn_Clear
  
  #Cont_3
  #Calendar
  #Btn_Clear2
  
  #DbgEdit
  #Btn_Quit
EndEnumeration

;- Constantes Diverses
#CCS_VERT = $00000080

;- Variables
Global hwnRb, g_hinst

Text1.s = "Liste et Combos"
Text2.s = "Explorateur"
Text3.s = "Calendrier"

;- Procedures
Procedure InsertBar(Text.s, Child.l, Parent.l, BarWidth.l, Index.l, BkColor.l, FgColor)
  rbBand.REBARBANDINFO
  
  rbBand\cbSize = SizeOf(REBARBANDINFO)
  rbBand\fMask  = #RBBIM_STYLE | #RBBIM_CHILD | #RBBIM_CHILDSIZE | #RBBIM_TEXT | #RBBIM_HEADERSIZE | #RBBIM_COLORS
  rbBand\fStyle = #RBBS_CHILDEDGE
  
  rbBand\clrBack    = BkColor
  rbBand\clrFore    = FgColor
  rbBand\lpText     = @Text
  rbBand\hwndChild  = Child
  rbBand\cyMinChild = BarWidth
  rbBand\cxHeader   = 25
  rbBand\cx         = BarWidth
  
  SendMessage_(Parent, #RB_INSERTBAND, Index, @rbBand)
EndProcedure

Procedure CreateRebar(Gadget, hwndOwner)
  rbi.REBARINFO
  icex.INITCOMMONCONTROLSEX
  
  icex\dwSize = SizeOf(INITCOMMONCONTROLSEX);
  icex\dwICC   = #ICC_COOL_CLASSES|#ICC_BAR_CLASSES;
  InitCommonControlsEx_(@icex);
  
  hwndRB = CreateWindowEx_(#WS_EX_TOOLWINDOW, "ReBarWindow32", #Null, #WS_CHILD|#WS_VISIBLE|#WS_CLIPSIBLINGS|#CCS_VERT , 0,0,0,0, hwndOwner, Gadget, g_hinst, #Null);
;/ Sous Windows XP, téléchargez la lib uxtheme. (Lien en bas du message)
;/ Pour les autres Windows, (98,ME, etc), désactivez cette ligne
  SetWindowTheme_(hwndRB, " ", " ")
;/
  
  ProcedureReturn hwndRB;
EndProcedure

;- Boucle principale
hwnd = OpenWindow(#Window_0, 300, 300, 800, 600, #PB_Window_SystemMenu|#PB_Window_ScreenCentered, "RebarTest",0)
g_hinst = GetModuleHandle_(#Null)

If CreateGadgetList(hwnd)
  hMainCont = ContainerGadget(#MainCont, 5, 5, 200, 590, #PB_Container_Raised)
  hwnRb   = CreateRebar(#Rebar, hMainCont)
  
  ;- Rebar 1
  hCont_1 = ContainerGadget(#Cont_1, 0, 0, 190, 590)
  hBtn_1  = ButtonGadget(#Btn_1, 45, 10, 100, 25, "Bouton 1")
  hList_1 = ListIconGadget(#List_1, 5, 40, 180, 350, "Liste 1", 125)
  AddGadgetColumn(#List_1, 1, "Valeur", 50)
  hCmb_1  = ComboBoxGadget(#Cmb_1, 5, 410, 180, 200)
  CloseGadgetList()
  
  ;- Rebar 2
  hCont_2 = ContainerGadget(#Cont_2, 0, 0, 190, 590)
  ExplorerTreeGadget(#Explorer, 5, 5, 180, 200, "C:\*.txt;*.pb")
  ButtonGadget(#Btn_Clear, 5, 210, 180, 20, "Effacer l'éditeur")
  CloseGadgetList()
  
  ;- Rebar 3
  hCont_3 = ContainerGadget(#Cont_3, 0, 0, 190, 590)
  CalendarGadget(#Calendar, 5, 5, 180, 200)
  ButtonGadget(#Btn_Clear2, 5, 210, 180, 20, "Effacer l'éditeur")
  
  CloseGadgetList()
  CloseGadgetList()
  
  
  ;- Retour à la liste de gadgets
  EditorGadget(#DbgEdit, 210, 5, 585, 560)
  ButtonGadget(#Btn_Quit, 450, 570, 100, 25, "Quitter")
  
  ;- Remplissage de la liste et du combo
  For i = 0 To 20
    AddGadgetItem(#Cmb_1,   -1, "Elément du combo " + Str(i))
    AddGadgetItem(#List_1,  -1, "Elément de la liste " + Str(i) + Chr(10) + Str(i))
  Next
  
  SetGadgetState(#Cmb_1, 0)
EndIf

;- Insertion des bandes
InsertBar(Text1, hCont_1, hwnRb, 190, 0, GetSysColor_(#COLOR_BTNFACE), $FF00FF)
InsertBar(Text2, hCont_2, hwnRb, 190, 1, GetSysColor_(#COLOR_BTNFACE), $FF0000)
InsertBar(Text3, hCont_3, hwnRb, 190, 2, GetSysColor_(#COLOR_BTNFACE), $0000FF)


;- Boucle
Repeat
  Select WaitWindowEvent()
    Case #PB_EventGadget
      Select EventGadgetID()
        ;- Evènements dans la bande 1
        Case #Btn_1
          AddGadgetItem(#DbgEdit, -1, GetGadgetText(EventGadgetID()))
        Case #List_1
          AddGadgetItem(#DbgEdit, -1, GetGadgetText(EventGadgetID()))
        Case #Cmb_1
          If EventType() = #PB_EventType_RightClick
            AddGadgetItem(#DbgEdit, -1, GetGadgetText(EventGadgetID()))
          EndIf
          
          ;- Evènements dans la bande 2
        Case #Btn_Clear
          ClearGadgetItemList(#DbgEdit)
          
        Case #Explorer
          If EventType() = #PB_EventType_LeftDoubleClick And GetGadgetState(#Explorer) = #PB_Explorer_File
            ClearGadgetItemList(#DbgEdit)
            
            If FileSize(GetGadgetText(#Explorer)) < 64900
              If ReadFile(0, GetGadgetText(#Explorer))
                Repeat
                  AddGadgetItem(#DbgEdit, -1, ReadString())
                Until Eof(0)
                CloseFile(0)
                
              EndIf
            EndIf
          EndIf
          
          
          ;- Evènements dans la bande 3
        Case #Calendar
          AddGadgetItem(#DbgEdit, -1, "La date choisie est le "+FormatDate("%dd %mm %yyyy", GetGadgetState(#Calendar)))
          
        Case #Btn_Clear2
          ClearGadgetItemList(#DbgEdit)
          
          ;- Retour à la fenêtre
        Case #Btn_Quit : quit = 1
          
      EndSelect
    Case #PB_EventCloseWindow : quit = 1
  EndSelect
Until quit = 1
End 
En cas de problème, téléchargez la librairie uxtheme ici

Publié : mar. 11/oct./2005 11:50
par fweil
Chris,

A part le SetWindowTheme_() que je n'ai pas le tout fonctionne bien.

Publié : mar. 11/oct./2005 11:55
par Chris
Le SetWindowTheme(), c'est pour désactiver les themes sous XP pour la barre, sinon, les titres en couleur n'apparaissent pas.

La lib en téléchargement est uniquement la déclaration des fonctions qui se trouvent dans la dll Uxtheme.dll de WinXP.

Sous les autres windows, il faut désactiver cette ligne.

Publié : mar. 11/oct./2005 13:05
par Anonyme2
C'est excellent l'effet, j'adopte :D

Publié : mar. 11/oct./2005 14:15
par Dr. Dri
C'est cool ^^
Faudrait le mettre en natif ce gadget!

(win98 SE -> nickel=)

Dri :10:

Publié : mar. 11/oct./2005 15:23
par comtois
ça marche super :)

purée va falloir que je m'y mette aux apis , je vais prendre du retard.

Publié : mar. 11/oct./2005 16:41
par nico
Génial. :D

Publié : mar. 11/oct./2005 23:14
par KarLKoX
Excellent #good

Publié : mer. 12/oct./2005 19:09
par Jacobus
Effectivement, c'est vraiment un truc sensas! 8O

Publié : sam. 18/févr./2006 5:36
par Guimauve
Bon, je viens enfin de retrouver le code original.

J'ai eu besoin de ce gadget pour un projet et j'ai modifié un peu les commandes. La création du RebarGadget et de ses items est un peu plus simple à faire. Je redonne le code modifié.

Code : Tout sélectionner

;-Constantes Fenêtres
Enumeration
   #Window_0
EndEnumeration

;-Constantes Gadgets
Enumeration
   
   #Rebar
   
   #RebarItem01
   #Btn_1
   #List_1
   #Cmb_1
   
   #RebarItem02
   #Explorer
   #Btn_Clear
   
   #RebarItem03
   #Calendar
   #Btn_Clear2
   
   #DbgEdit
   #Btn_Quit
EndEnumeration

;- Constantes Diverses
#CCS_VERT = $00000080

;- Variables
; Global hwnRb, g_hinst

Text1.s = "Liste et Combos"
Text2.s = "Explorateur"
Text3.s = "Calendrier"

;- Procedures
Procedure InsertReBarItem(hWndRebar.l, RebarItemID.l, Text.s, BarWidth.l, Index.l, BkColor.l, FgColor)
   
   hItemCont = ContainerGadget(RebarItemID, 0, 0, 0, 0)
   
   rbBand.REBARBANDINFO
   
   rbBand\cbSize = SizeOf(REBARBANDINFO)
   rbBand\fMask  = #RBBIM_STYLE | #RBBIM_CHILD | #RBBIM_CHILDSIZE | #RBBIM_TEXT | #RBBIM_HEADERSIZE | #RBBIM_COLORS
   rbBand\fStyle = #RBBS_CHILDEDGE
   
   rbBand\clrBack    = BkColor
   rbBand\clrFore    = FgColor
   rbBand\lpText     = @Text
   rbBand\hwndChild  = hItemCont
   rbBand\cyMinChild = BarWidth
   rbBand\cxHeader   = 30
   rbBand\cx         = BarWidth
   
   SendMessage_(hWndRebar, #RB_INSERTBAND, Index, @rbBand)
   
EndProcedure

Procedure RebarGadget(GadgetID, x, y, Width, Height)
   
   hMainCont = ContainerGadget(GadgetID, x, y, Width, Height, #PB_Container_Raised)
   
   rbi.REBARINFO
   icex.INITCOMMONCONTROLSEX
   
   icex\dwSize = SizeOf(INITCOMMONCONTROLSEX);
   icex\dwICC   = #ICC_COOL_CLASSES|#ICC_BAR_CLASSES
   InitCommonControlsEx_(@icex);
   
   hwndRB = CreateWindowEx_(#WS_EX_TOOLWINDOW, "ReBarWindow32", #Null, #WS_CHILD|#WS_VISIBLE|#WS_CLIPSIBLINGS|#CCS_VERT , 0,0,0,0, hMainCont, GadgetID, 0, #Null);
   ;/ Sous Windows XP, téléchargez la lib uxtheme. (Lien en bas du message)
   ;/ Pour les autres Windows, (98,ME, etc), désactivez cette ligne
   ; SetWindowTheme_(hwndRB, " ", " ")
   ;/
   
   ProcedureReturn hwndRB;
EndProcedure

;- Boucle principale
hwnd = OpenWindow(#Window_0, 300, 300, 800, 600, #PB_Window_SystemMenu|#PB_Window_ScreenCentered, "RebarTest",0)
; g_hinst = GetModuleHandle_(#Null)

If CreateGadgetList(hwnd)
   
   RebarHandle = RebarGadget(#Rebar, 5, 5, 200, 400);>
      
      ;- Rebar 1
      InsertReBarItem(RebarHandle, #RebarItem01, Text1, 185, 0, GetSysColor_(#COLOR_BTNFACE), 0);>
         ButtonGadget(#Btn_1, 45, 10, 100, 25, "Bouton 1")
         ListIconGadget(#List_1, 5, 40, 180, 350, "Liste 1", 125)
         AddGadgetColumn(#List_1, 1, "Valeur", 50)
         ComboBoxGadget(#Cmb_1, 5, 410, 180, 200)
      CloseGadgetList();<
      
      ;- Rebar 2
      InsertReBarItem(RebarHandle, #RebarItem02, Text2, 185, 1, GetSysColor_(#COLOR_BTNFACE), 0);>
         ExplorerTreeGadget(#Explorer, 5, 5, 180, 200, "C:\*.txt;*.pb")
         ButtonGadget(#Btn_Clear, 5, 210, 180, 20, "Effacer l'éditeur")
      CloseGadgetList();<
      
      ;- Rebar 3
      InsertReBarItem(RebarHandle, #RebarItem03, Text3, 185, 2, GetSysColor_(#COLOR_BTNFACE), 0);>
         CalendarGadget(#Calendar, 5, 5, 180, 200)
         ButtonGadget(#Btn_Clear2, 5, 210, 180, 20, "Effacer l'éditeur")
      CloseGadgetList();<
      
   CloseGadgetList();<
   
   
   ;- Retour à la liste de gadgets
   EditorGadget(#DbgEdit, 210, 5, 585, 560)
   ButtonGadget(#Btn_Quit, 450, 570, 100, 25, "Quitter")
   
   ;- Remplissage de la liste et du combo
   For i = 0 To 20
      AddGadgetItem(#Cmb_1,   -1, "Elément du combo " + Str(i))
      AddGadgetItem(#List_1,  -1, "Elément de la liste " + Str(i) + Chr(10) + Str(i))
   Next
   
   SetGadgetState(#Cmb_1, 0)
EndIf


;- Boucle
Repeat
   Select WaitWindowEvent()
      Case #PB_Event_Gadget
         Select EventGadget()
            ;- Evènements dans la bande 1
            Case #Btn_1
               AddGadgetItem(#DbgEdit, -1, GetGadgetText(EventGadget()))
            Case #List_1
               AddGadgetItem(#DbgEdit, -1, GetGadgetText(EventGadget()))
            Case #Cmb_1
               If EventType() = #PB_EventType_RightClick
                  AddGadgetItem(#DbgEdit, -1, GetGadgetText(EventGadget()))
               EndIf
               
               ;- Evènements dans la bande 2
            Case #Btn_Clear
               ClearGadgetItemList(#DbgEdit)
               
            Case #Explorer
               If EventType() = #PB_EventType_LeftDoubleClick And GetGadgetState(#Explorer) = #PB_Explorer_File
                  ClearGadgetItemList(#DbgEdit)
                  
                  If FileSize(GetGadgetText(#Explorer)) < 64900
                     If ReadFile(0, GetGadgetText(#Explorer))
                        Repeat
                           AddGadgetItem(#DbgEdit, -1, ReadString(0))
                        Until Eof(0)
                        CloseFile(0)
                        
                     EndIf
                  EndIf
               EndIf
               
               
               ;- Evènements dans la bande 3
            Case #Calendar
               AddGadgetItem(#DbgEdit, -1, "La date choisie est le "+FormatDate("%dd %mm %yyyy", GetGadgetState(#Calendar)))
               
            Case #Btn_Clear2
               ClearGadgetItemList(#DbgEdit)
               
               ;- Retour à la fenêtre
            Case #Btn_Quit 
               quit = 1
               
         EndSelect
         
      Case #PB_Event_CloseWindow 
         quit = 1
         
   EndSelect
Until quit = 1

End
Faudrait peut-être faire une suggestion pour que ce Gadget soit ajouter parmis les standards de PB.

A+
Guimauve

Publié : sam. 18/févr./2006 11:55
par CameleonTH
C'est excellent cette ReBar

Publié : sam. 18/févr./2006 12:23
par CameleonTH
Sur le forum anglais j'ai trouver un aute exmple mais qui n'est pas de moi :D

Code : Tout sélectionner

; Rebar Control by Sparkie 07/22/2004

#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, #PB_Window_ScreenCentered | #PB_Window_SystemMenu, "Rebar Control")
  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(), hStGad, hTbGad, hCbGad)
  EndIf
EndIf
     
Repeat
         
  event = WaitWindowEvent()
 
    Select event
     
      Case #PB_EventMenu
       
        If event = #PB_EventMenu
          SetGadgetText(0, "ToolBar ID: " + Str(EventMenuID()))
        EndIf
     
      Case #PB_EventGadget
       
        If EventGadgetID() = 1
          SetGadgetText(0, GetGadgetText(1))
        EndIf
       
       
      Case #PB_Event_CloseWindow
        quit = #True
             
    EndSelect
         
Until quit = #True
       
End 

Publié : lun. 06/mars/2006 13:09
par Ulix
Le Rebar est excellent ! :idea:

Y a t-il quelqu'un pour nous en faire une lib, en attentant qu'il soit en natif dans le PB (version 5 ou 6, là je suis mauvaise langue :oops: )

J'attends déjà une grille... l'espoir fait vivre :(