Page 1 of 1

Gadgets in several windows

Posted: Mon Sep 30, 2024 12:13 am
by ricardo
I have not used PureBasic much for several years and I have forgotten something basic:

I have created 3 windows and now I want to create a gadget that appears in the first window. When I have already created the 3 windows and each one with its own gadgets, but I want to dynamically create a gadget in the first window, how do I do it?

I hope I have explained the matter well.

Thanks.

Re: Gadgets in several windows

Posted: Mon Sep 30, 2024 12:54 am
by ricardo
Its UseGadgetList() right?

Re: Gadgets in several windows

Posted: Mon Sep 30, 2024 1:01 am
by Demivec
You would have to use UseGadgetList() and specify the window ID for the window in question.

Re: Gadgets in several windows

Posted: Mon Sep 30, 2024 5:57 am
by ricardo
Demivec wrote: Mon Sep 30, 2024 1:01 am You would have to use UseGadgetList() and specify the window ID for the window in question.
Yes, i remeber the solution after posting, Thanks.

Re: Gadgets in several windows

Posted: Mon Sep 30, 2024 6:30 am
by TI-994A
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. :D

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.