How to find the Container Gadget?
How to find the Container Gadget?
Hi experts,
is there a way to find out what the container gadget of a child gadget is, knowing the child gadget? there must be a way - but i could not find it. Since PB ResizeGadget() fucntion does resize a gadget within its container, so there should be an easy way to find out the 'parent' gadget? Any idea ?
Thanks
is there a way to find out what the container gadget of a child gadget is, knowing the child gadget? there must be a way - but i could not find it. Since PB ResizeGadget() fucntion does resize a gadget within its container, so there should be an easy way to find out the 'parent' gadget? Any idea ?
Thanks
- NicknameFJ
- User
- Posts: 90
- Joined: Tue Mar 17, 2009 6:36 pm
- Location: Germany
Re: How to find the Container Gadget?
Hello Said,
maybe GetParent_(hwnd)
will help.
NicknameFJ
maybe GetParent_(hwnd)
will help.
NicknameFJ
PS: Sorry for my weird english, but english is not my native language.


Re: How to find the Container Gadget?
That's a missing feature in my opinion. GetGadgetParent/GetGadgetChildren would be really useful 

Re: How to find the Container Gadget?
Hi said. NicknameFJ's correct; you can use the GetParent() API function to get the handle of the parent window, but you'll also need to use GetDlgCtrlID() to determine its PureBasic identifier. Here's a sample code:said wrote:...is there a way to find out what the container gadget of a child gadget is, knowing the child gadget? ...an easy way to find out the 'parent' gadget?
Code: Select all
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, 0, 0, 250, 100, "GetParent ID:", wFlags)
ContainerGadget(123, 25, 25, 200, 50)
SetGadgetColor(123, #PB_Gadget_BackColor, #Cyan)
ButtonGadget(2, 10, 10, 180, 30, "Button in Container")
CloseGadgetList()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 2
Select EventType()
Case #PB_EventType_LeftClick
newLabel.s = Str(GetDlgCtrlID_(GetParent_(GadgetID(2))))
SetGadgetText(2, "My Papa is Gadget #" + newLabel)
EndSelect
EndSelect
EndSelect
Until appQuit
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 

Re: How to find the Container Gadget?
Thank you NicknameFJ and Polo, however i missed to mention that i am more interested in preferably a native PB way or at least a crossplatform.
So you think we should add this in the new feature requests along with the suggested GetGadgetChildren, i find this quite useful
So you think we should add this in the new feature requests along with the suggested GetGadgetChildren, i find this quite useful
Re: How to find the Container Gadget?
TI-994A wrote:Hi said. NicknameFJ's correct; you can use the GetParent() API function to get the handle of the parent window, but you'll also need to use GetDlgCtrlID() to determine its PureBasic identifier. Here's a sample code:said wrote:...is there a way to find out what the container gadget of a child gadget is, knowing the child gadget? ...an easy way to find out the 'parent' gadget?It's a Windows only solution, but I hope it helps.Code: Select all
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered OpenWindow(0, 0, 0, 250, 100, "GetParent ID:", wFlags) ContainerGadget(123, 25, 25, 200, 50) SetGadgetColor(123, #PB_Gadget_BackColor, #Cyan) ButtonGadget(2, 10, 10, 180, 30, "Button in Container") CloseGadgetList() Repeat Select WaitWindowEvent() Case #PB_Event_CloseWindow appQuit = 1 Case #PB_Event_Gadget Select EventGadget() Case 2 Select EventType() Case #PB_EventType_LeftClick newLabel.s = Str(GetDlgCtrlID_(GetParent_(GadgetID(2)))) SetGadgetText(2, "My Papa is Gadget #" + newLabel) EndSelect EndSelect EndSelect Until appQuit
Thank you TI-994A for the effort and the sample code, we have a windows part so far!
Re: How to find the Container Gadget?
http://www.forums.purebasic.com/english ... =3&t=49900said wrote:Thank you NicknameFJ and Polo, however i missed to mention that i am more interested in preferably a native PB way or at least a crossplatform.
So you think we should add this in the new feature requests along with the suggested GetGadgetChildren, i find this quite useful


Re: How to find the Container Gadget?
Polo wrote:http://www.forums.purebasic.com/english ... =3&t=49900said wrote:Thank you NicknameFJ and Polo, however i missed to mention that i am more interested in preferably a native PB way or at least a crossplatform.
So you think we should add this in the new feature requests along with the suggested GetGadgetChildren, i find this quite useful
![]()

-
- Enthusiast
- Posts: 542
- Joined: Tue Apr 24, 2012 5:08 pm
- Location: Ontario, Canada
Re: How to find the Container Gadget?
The following technique works well - we use it all the time. It's cross platform and doesn't require any new PB features.
In practice, we store the address of the OOP instance that represents the gadget. One of the properties in the gadget's class always points to the parent container.
Code: Select all
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, 0, 0, 250, 100, "GetParent ID:", wFlags)
ContainerGadget(123, 25, 25, 200, 50)
ButtonGadget(2, 10, 10, 180, 30, "Button in Container")
SetGadgetData(2, 123)
CloseGadgetList()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 2
Select EventType()
Case #PB_EventType_LeftClick
SetGadgetText(2, "My Papa is Gadget #" + Str(GetGadgetData(2)))
EndSelect
EndSelect
EndSelect
Until appQuit
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
~ Spike Milligan
Re: How to find the Container Gadget?
Basically I like the idea of having something like GetParent/SetParent, but I really like your workaround as well. It's a good idea and works flawlessly! Thanks!Boris wrote:The following technique works well - we use it all the time. It's cross platform and doesn't require any new PB features.
Code:
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, 0, 0, 250, 100, "GetParent ID:", wFlags)
ContainerGadget(123, 25, 25, 200, 50)
ButtonGadget(2, 10, 10, 180, 30, "Button in Container")
SetGadgetData(2, 123)
CloseGadgetList()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 2
Select EventType()
Case #PB_EventType_LeftClick
SetGadgetText(2, "My Papa is Gadget #" + Str(GetGadgetData(2)))
EndSelect
EndSelect
EndSelect
Until appQuit
In practice, we store the address of the OOP instance that represents the gadget. One of the properties in the gadget's class always points to the parent container.
cheers,
bembulak
bembulak
-
- Enthusiast
- Posts: 542
- Joined: Tue Apr 24, 2012 5:08 pm
- Location: Ontario, Canada
Re: How to find the Container Gadget?
The above example can be modified to show how large amounts of data can be linked to a gadget. This technique also eliminates the need to have huge select statements in the event routine, as the event handling code can be located immediately. This is particulary important in large applications that may have hundreds or thousands of gadgets.
Code: Select all
Structure GadgetInfo
*EventProcedure.i
ParentContainer.i
;
; other gadget properties can be included here
;
EndStructure
Define Button1.GadgetInfo
Define *GadgetPtr.GadgetInfo
Procedure Button1Events(*Ptr.GadgetInfo)
Select EventType()
Case #PB_EventType_LeftClick
SetGadgetText(2, "My Papa is Gadget #" + Str(*Ptr\ParentContainer))
EndSelect
EndProcedure
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, 0, 0, 250, 100, "GetParent ID:", wFlags)
ContainerGadget(123, 25, 25, 200, 50)
ButtonGadget(2, 10, 10, 180, 30, "Button in Container")
Button1\EventProcedure = @Button1Events()
Button1\ParentContainer = 123
SetGadgetData(2, @Button1)
CloseGadgetList()
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
appQuit = 1
Case #PB_Event_Gadget
*GadgetPtr = GetGadgetData(EventGadget())
If *GadgetPtr <> 0
CallFunctionFast(*GadgetPtr\EventProcedure, *GadgetPtr)
EndIf
EndSelect
Until appQuit
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
~ Spike Milligan
Re: How to find the Container Gadget?
@BorisTheOld thank you, very helpful