What window does a gadget belong to?

Just starting out? Need help? Post your questions and find answers here.
Damion12
User
User
Posts: 81
Joined: Tue Oct 30, 2012 1:39 am

What window does a gadget belong to?

Post by Damion12 »

how to tell gadget is in what window?

like:

MyWindow = GadgetBelongsToWhatWindow( SomeGadget )
missile69
User
User
Posts: 25
Joined: Mon Feb 21, 2011 12:15 pm

Re: What window does a gadget belong to?

Post 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
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: What window does a gadget belong to?

Post 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)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
PB Fanatic
User
User
Posts: 49
Joined: Wed Dec 17, 2014 11:54 am

Re: What window does a gadget belong to?

Post by PB Fanatic »

Code: Select all

Macro GadgetWindow(gad)
  GetProp_(GetParent_(GadgetID(gad)),"PB_WindowID")-1
EndMacro
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: What window does a gadget belong to?

Post 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.
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: What window does a gadget belong to?

Post 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
Post Reply