Page 1 of 1

What window does a gadget belong to?

Posted: Wed Dec 17, 2014 12:58 am
by Damion12
how to tell gadget is in what window?

like:

MyWindow = GadgetBelongsToWhatWindow( SomeGadget )

Re: What window does a gadget belong to?

Posted: Wed Dec 17, 2014 2:27 am
by missile69
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

Re: What window does a gadget belong to?

Posted: Wed Dec 17, 2014 4:59 am
by IdeasVacuum
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:

Code: Select all

              SetGadgetData(#MyStringGadget01, #MyWin02)
iWinID.i = GetGadgetData(#MyStringGadget01)

Re: What window does a gadget belong to?

Posted: Wed Dec 17, 2014 12:01 pm
by PB Fanatic

Code: Select all

Macro GadgetWindow(gad)
  GetProp_(GetParent_(GadgetID(gad)),"PB_WindowID")-1
EndMacro

Re: What window does a gadget belong to?

Posted: Wed Dec 17, 2014 12:40 pm
by Bisonte
PB Fanatic wrote:

Code: Select all

Macro GadgetWindow(gad)
  GetProp_(GetParent_(GadgetID(gad)),"PB_WindowID")-1
EndMacro
This does'nt work, if you have a gadget on a containergadget.

Re: What window does a gadget belong to?

Posted: Wed Dec 17, 2014 6:27 pm
by jassing
PB Fanatic wrote:

Code: Select all

Macro GadgetWindow(gad)
  GetProp_(GetParent_(GadgetID(gad)),"PB_WindowID")-1
EndMacro
That's pretty slick -- I always forget about the added properties...
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