Petit exemple, comme ça, pour rien

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Petit exemple, comme ça, pour rien

Message 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
Dernière modification par Chris le mar. 11/oct./2005 12:13, modifié 1 fois.
fweil
Messages : 505
Inscription : dim. 16/mai/2004 17:50
Localisation : Bayonne (64)
Contact :

Message par fweil »

Chris,

A part le SetWindowTheme_() que je n'ai pas le tout fonctionne bien.
Mon avatar reproduit l'image de 4x1.8m présentée au 'Salon international du meuble de Paris' en janvier 2004, dans l'exposition 'Shades' réunisant 22 créateurs autour de Matt Sindall. L'original est un stratifié en 150 dpi.
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message 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.
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Message par Anonyme2 »

C'est excellent l'effet, j'adopte :D
Dr. Dri
Messages : 2527
Inscription : ven. 23/janv./2004 18:10

Message par Dr. Dri »

C'est cool ^^
Faudrait le mettre en natif ce gadget!

(win98 SE -> nickel=)

Dri :10:
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Message par comtois »

ça marche super :)

purée va falloir que je m'y mette aux apis , je vais prendre du retard.
http://purebasic.developpez.com/
Je ne réponds à aucune question technique en PV, utilisez le forum, il est fait pour ça, et la réponse peut profiter à tous.
nico
Messages : 3702
Inscription : ven. 13/févr./2004 0:57

Message par nico »

Génial. :D
KarLKoX
Messages : 1191
Inscription : jeu. 26/févr./2004 15:36
Localisation : France
Contact :

Message par KarLKoX »

Excellent #good
"Qui baise trop bouffe un poil." P. Desproges
Avatar de l’utilisateur
Jacobus
Messages : 1559
Inscription : mar. 06/avr./2004 10:35
Contact :

Message par Jacobus »

Effectivement, c'est vraiment un truc sensas! 8O
Quand tous les glands seront tombés, les feuilles dispersées, la vigueur retombée... Dans la morne solitude, ancré au coeur de ses racines, c'est de sa force maturité qu'il renaîtra en pleine magnificence...Jacobus.
Guimauve
Messages : 1015
Inscription : mer. 11/févr./2004 0:32
Localisation : Québec, Canada

Message 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
CameleonTH
Messages : 333
Inscription : sam. 25/juin/2005 11:18
Localisation : Laon (02)
Contact :

Message par CameleonTH »

C'est excellent cette ReBar
CameleonTH
Messages : 333
Inscription : sam. 25/juin/2005 11:18
Localisation : Laon (02)
Contact :

Message 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 
Avatar de l’utilisateur
Ulix
Messages : 315
Inscription : ven. 04/juin/2004 14:27
Localisation : Frontignan

Message 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 :(
Répondre