how to tell gadget is in what window?
like:
MyWindow = GadgetBelongsToWhatWindow( SomeGadget )
What window does a gadget belong to?
Re: What window does a gadget belong to?
There's currently no built in PB command to do this but there is some nice code by mestnyi in the feature request board that does what you're asking. See here: http://www.purebasic.fr/english/viewtop ... =3&t=59431
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: What window does a gadget belong to?
Well, that is something you should already know if the windows and their gadgets are defined by you for your app.......
Something you can do is store data with any gadget, so you could:
Something you can do is store data with any gadget, so you could:
Code: Select all
SetGadgetData(#MyStringGadget01, #MyWin02)
iWinID.i = GetGadgetData(#MyStringGadget01)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
-
- User
- Posts: 49
- Joined: Wed Dec 17, 2014 11:54 am
Re: What window does a gadget belong to?
Code: Select all
Macro GadgetWindow(gad)
GetProp_(GetParent_(GadgetID(gad)),"PB_WindowID")-1
EndMacro
Re: What window does a gadget belong to?
This does'nt work, if you have a gadget on a containergadget.PB Fanatic wrote:Code: Select all
Macro GadgetWindow(gad) GetProp_(GetParent_(GadgetID(gad)),"PB_WindowID")-1 EndMacro
Re: What window does a gadget belong to?
That's pretty slick -- I always forget about the added properties...PB Fanatic wrote:Code: Select all
Macro GadgetWindow(gad) GetProp_(GetParent_(GadgetID(gad)),"PB_WindowID")-1 EndMacro
As was pointed out; if the gadget is in a container, this won't work;but you could easily cycle thru until the parent is not a container, or is a window....
Quick-n-dirty:
Code: Select all
Procedure GetGadgetWindow(nGadget)
Protected nWindow, hParent, hGadget
If IsGadget(nGadget)
hGadget = GadgetID(nGadget)
Repeat
hParent = GetParent_(hGadget)
nWindow = GetProp_(hParent,"PB_WindowID")
If nWindow=0
hGadget = hParent
Else
nWindow - 1
EndIf
Until IsWindow(nWindow)
else
nWindow=-1
EndIf
ProcedureReturn nWindow
EndProcedure