Hi,
I like to do a function that loops through all gadgets of a window to change their alignment or font. For example, I want to set the font of all text- and string-gadgets of a window to some smaller one. No, I don't want to use SetGadgetFont() on more than 30 gadgets (big configuration dialog). Is there a way to get a list of all gadgets of a window and their gadget type?
I need this for Linux and Windows.
Best
Volker
How to loop through all gadgets of a window?
Re: How to loop through all gadgets of a window?
Not natively. Just write our own functions that add the gadgets to a list
to be able to keep track of them.
Just be creative.
to be able to keep track of them.

Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Re: How to loop through all gadgets of a window?
If you use enumerated constants it's straightforward, just loop from the first to the last:
If you use #PB_Any, you need to put all gadgets in a list or map and use a foreach loop.
This is the only crossplatform way of looping over all gadgets. Though if you want all gadgets of a certain type to have a particular appearance, I suggest you make a procedure to create them like you want them to be:
Code: Select all
For I = = #FirstGadget to #LastGadget
Next
This is the only crossplatform way of looping over all gadgets. Though if you want all gadgets of a certain type to have a particular appearance, I suggest you make a procedure to create them like you want them to be:
Code: Select all
Procedure H3TextGadget(Gadget, x, y, w, h, Text.s, Flags=0)
Static Font.i
Protected Handle.i
If Not Font
Font = LoadFont(#PB_Any, "Trebuchet MS", 10, #PB_Font_Bold)
EndIf
Handle = TextGadget(Gadget, x, y, w, h, Text, Flags)
If Gadget = #PB_Any
Gadget = Handle
EndIf
SetGadgetFont(Gadget, FontID(Font))
ProcedureReturn Handle
EndProcedure
W = 512
H = 384
OpenWindow(0, 0, 0, W, H, "", #PB_Window_ScreenCentered | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget)
H3TextGadget(#PB_Any, 10, 10, 200, 25, "Header Size 3")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
CloseWindow(0)
Break
EndSelect
ForEver
Re: How to loop through all gadgets of a window?
Windows :
From RSBasics WinAPI-Library
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 "OS ID of Gadget: "+Str(hwnd)
Debug "PureBasic-ID of Gadgets: "+Str(GetProp_(hwnd, "PB_ID"))
Debug "GadgetType: "+String2$
Debug "Gadgettext: "+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
Re: How to loop through all gadgets of a window?
Thanks, good ideas! I will take a look.
Best,
Kukulkan
Best,
Kukulkan