Gadgets in several windows

Just starting out? Need help? Post your questions and find answers here.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Gadgets in several windows

Post 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.
ARGENTINA WORLD CHAMPION
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Gadgets in several windows

Post by ricardo »

Its UseGadgetList() right?
ARGENTINA WORLD CHAMPION
User avatar
Demivec
Addict
Addict
Posts: 4281
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Gadgets in several windows

Post by Demivec »

You would have to use UseGadgetList() and specify the window ID for the window in question.
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Re: Gadgets in several windows

Post 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.
ARGENTINA WORLD CHAMPION
User avatar
TI-994A
Addict
Addict
Posts: 2751
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Gadgets in several windows

Post 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.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply