Change all Gadget to Explorer Theme

Share your advanced PureBasic knowledge/code with the community.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Change all Gadget to Explorer Theme

Post by mk-soft »

Change all Gadget to Explorer Theme :wink:

Code: Select all

;-TOP

; ***************************************************************************************

; Import internal function ------------------------------------------------------------

CompilerIf #PB_Compiler_OS = #PB_OS_Windows
  Import ""
    PB_Object_EnumerateStart( PB_Objects )
    PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
    PB_Object_EnumerateAbort( PB_Objects )
    PB_Object_GetObject( PB_Object , DynamicOrArrayID)
    PB_Window_Objects.i
    PB_Gadget_Objects.i
  EndImport
CompilerElse
  ImportC ""
    PB_Object_EnumerateStart( PB_Objects )
    PB_Object_EnumerateNext( PB_Objects, *ID.Integer )
    PB_Object_EnumerateAbort( PB_Objects )
    PB_Object_GetObject( PB_Object , DynamicOrArrayID)
    PB_Window_Objects.i
    PB_Gadget_Objects.i
  EndImport
CompilerEndIf

Procedure SetExplorerTheme(State=#True)
  Protected gadget, theme.s
  If State
    theme = "Explorer"
  Else
    theme = ""
  EndIf
  PB_Object_EnumerateStart(PB_Gadget_Objects)
  While PB_Object_EnumerateNext(PB_Gadget_Objects, @gadget)
    SetWindowTheme_(GadgetID(gadget), @Theme, 0)
  Wend
  PB_Object_EnumerateAbort(PB_Gadget_Objects)
EndProcedure

; ***************************************************************************************
;
; ------------------------------------------------------------
;
;   PureBasic - Gadget example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

#WindowWidth  = 640
#WindowHeight = 480


Procedure OnSizeWindow()
  ResizeGadget(5, #PB_Ignore, #PB_Ignore, WindowWidth(0)-10, WindowHeight(0)-45) ; Our 'master' splitter gadget
EndProcedure


If OpenWindow(0, 100, 120, #WindowWidth, #WindowHeight, "PureBasic - Gadget Demonstration", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)

  HyperLinkGadget(7, 10, 5, 180, 30, "This is a green hyperlink", RGB(0,255,0))
  HyperLinkGadget(8, 200, 5, 220, 30, "This is a red hyperlink", RGB(255,0,0))
  
  SetGadgetFont(8, LoadFont(0, "courier", 10, #PB_Font_Underline | #PB_Font_Bold))

  ListIconGadget(0, 115, 10, 100, 190, "Test", 100)
  For k=0 To 10
    AddGadgetItem(0, -1, "Element "+Str(k))
  Next
  
  ExplorerListGadget(1, 115, 10, 100, 190, GetHomeDirectory(), #PB_Explorer_AlwaysShowSelection|#PB_Explorer_FullRowSelect|#PB_Explorer_MultiSelect)

  TreeGadget(3, 115, 10, 100, 190)
  
  For k=0 To 10
    AddGadgetItem(3, -1, "Hello "+Str(k))
  Next

  PanelGadget(6, 0, 0, 400, 400)
    For k=0 To 5
      AddGadgetItem(6, -1, "Line "+Str(k))
      ButtonGadget(12+k, 10, 10, 100, 20, "Test"+Str(k))
    Next
  CloseGadgetList()

  SplitterGadget(2, 0, 0, #WindowWidth/2, #WindowHeight/2, 1, 0)
  SplitterGadget(4, 0, 0, #WindowWidth, #WindowHeight, 3, 2, #PB_Splitter_Vertical | #PB_Splitter_Separator)
  SplitterGadget(5, 5, 40, #WindowWidth-10, #WindowHeight-45, 4, 6, #PB_Splitter_Vertical)
  
  SetGadgetState(5, 500)
  
  ; Use BindEvent() to have a realtime window sizing
  BindEvent(#PB_Event_SizeWindow, @OnSizeWindow())
  
  SetExplorerTheme()
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Gadget
      
      Select EventGadget()
        Case 8
          SetGadgetState(5, 333)
          SetGadgetState(2, 333)
          
      EndSelect
    EndIf
  
  Until Event = #PB_Event_CloseWindow
EndIf

End  
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Change all Gadget to Explorer Theme

Post by RSBasic »

Thanks for sharing. Works very well.

Are the PB internal functions (e.g. PB_Object_EnumerateStart) safe? Not that they are not renamed or changed.

Alternatively, EnumChildWindows_():

Code: Select all

EnableExplicit

Define EventID

Procedure ListWindows(hwnd,Param)
  Protected String$
  Protected String2$
  
  String$ = Space(250)
  String2$ = Space(1024)
  GetWindowText_(hwnd,String$,250)
  GetClassName_(hwnd,@String2$,Len(String2$))
  
  Debug "Handle: "+Str(hwnd)
  Debug "PB-Number: "+Str(GetProp_(hwnd, "PB_ID"))
  Debug "Type: "+String2$
  Debug "Content: "+String$
  Debug "--------------------------------------------------------------------"
  
  ProcedureReturn #True
EndProcedure

If OpenWindow(0,0,0,500,400,"Window",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ButtonGadget(1,10,10,100,20,"Hallo Button",0)
  StringGadget(2,120,10,100,20,"Hallo Edit",0)
  ListViewGadget(3,10,40,100,100,0)
  
  EnumChildWindows_(WindowID(0),@ListWindows(),0)
  
  Repeat
    EventID=WaitWindowEvent()
    If EventID = #PB_Event_CloseWindow
      End
    EndIf
  ForEver
EndIf
Image
Image
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Change all Gadget to Explorer Theme

Post by mk-soft »

Part of the SDK from Purebasic.
So if that doesn't change.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply