ricardo wrote: Mon Sep 30, 2024 12:13 amI have not used PureBasic much for several years and I have forgotten something basic...
A courtesy refresher, and also for the benefit of others who might stumble upon this thread.
The basics of the UseGadgetList() function:
Code: Select all
; gadget list will belong to window 1
window1 = OpenWindow(#PB_Any, 200, 200, 300, 300, "Window 1",
#PB_Window_SystemMenu)
; gadget list will belong to window 2
window2 = OpenWindow(#PB_Any, 550, 200, 300, 300, "Window 2",
#PB_Window_SystemMenu)
UseGadgetList(WindowID(window1)) ; gadget list will belong to window 1
win1button1 = ButtonGadget(#PB_Any, 10, 10, 150, 25, "Win1 Button1")
UseGadgetList(WindowID(window2)) ; gadget list will belong to window 2
win2Button1 = ButtonGadget(#PB_Any, 10, 10, 150, 25, "Win2 Button1")
UseGadgetList(WindowID(window1)) ; gadget list will belong to window 1
win1Button2 = ButtonGadget(#PB_Any, 10, 45, 150, 25, "Win1 Button2")
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
The UseGadgetList() function in conjunction with containers (canvases, panels, frames, scroll areas):
Code: Select all
; gadget list will belong to window 1
window1 = OpenWindow(#PB_Any, 200, 200, 300, 300, "Window 1",
#PB_Window_SystemMenu)
; gadget list will belong to canvas 1
canvas1 = CanvasGadget(#PB_Any, 10, 90, 280, 200,
#PB_Canvas_Container)
; gadget list will belong to window 2
window2 = OpenWindow(#PB_Any, 550, 200, 300, 300, "Window 2",
#PB_Window_SystemMenu)
UseGadgetList(WindowID(window1)) ; gadget list will belong to canvas 1
win1button1 = ButtonGadget(#PB_Any, 10, 10, 150, 25, "Win1 Button1")
UseGadgetList(WindowID(window2)) ; gadget list will belong to window 2
win2Button1 = ButtonGadget(#PB_Any, 10, 10, 150, 25, "Win2 Button1")
UseGadgetList(WindowID(window1)) ; gadget list will belong to canvas 1
win1Button2 = ButtonGadget(#PB_Any, 10, 45, 150, 25, "Win1 Button2")
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
The OpenGadgetList() and the CloseGadgetList() functions:
Code: Select all
; gadget list will belong to window 1
window1 = OpenWindow(#PB_Any, 200, 200, 300, 300, "Window 1",
#PB_Window_SystemMenu)
; gadget list will belong to canvas 1
canvas1 = CanvasGadget(#PB_Any, 10, 90, 280, 200,
#PB_Canvas_Container)
CloseGadgetList() ; gadget list will revert to window 1
; gadget list will belong to window 2
window2 = OpenWindow(#PB_Any, 550, 200, 300, 300, "Window 2",
#PB_Window_SystemMenu)
UseGadgetList(WindowID(window1)) ; gadget list will belong to window 1
win1button1 = ButtonGadget(#PB_Any, 10, 10, 150, 25, "Win1 Button1")
UseGadgetList(WindowID(window2)) ; gadget list will belong to window 2
win2Button1 = ButtonGadget(#PB_Any, 10, 10, 150, 25, "Win2 Button1")
UseGadgetList(WindowID(window1)) ; gadget list will belong to window 1
win1Button2 = ButtonGadget(#PB_Any, 10, 45, 150, 25, "Win1 Button2")
OpenGadgetList(canvas1) ; gadget list will belong to canvas 1
canButton1 = ButtonGadget(#PB_Any, 65, 40, 150, 25, "Canvas Button1")
CloseGadgetList() ; gadget list will revert to window 1
ButtonGadget(#PB_Any, 150, 10, 150, 25, "Win1 Button3")
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
It should be noted that
gadget list values could be stored in variables once and reused when required, to avoid the overhead of repeatedly calling the
UseGadgetList() function. This is not implemented here simply for the sake of clarity.