[Solved] Get hWnd of a #PB_Any gadget?

Windows specific forum
BarryG
Addict
Addict
Posts: 3331
Joined: Thu Apr 18, 2019 8:17 am

[Solved] Get hWnd of a #PB_Any gadget?

Post by BarryG »

How do I get the handle (hWnd) of a gadget that was created with #PB_Any? As you can see below, GadgetID() doesn't return it (but it does with hard-coded gadget numbers instead of #PB_Any). I need it so I can use SetProp_() with it. Thanks.

Code: Select all

If OpenWindow(0, 100, 200, 300, 100, "ButtonGadget", #PB_Window_SystemMenu)
  bg = ButtonGadget(#PB_Any, 10, 10, 200, 30, "Button")
  Debug bg ; 38539160
  Debug GadgetID(bg) ; 41945080
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
It works with hard-coded gadget numbers, but I need #PB_Any for my project:

Code: Select all

If OpenWindow(0, 100, 200, 300, 100, "ButtonGadget", #PB_Window_SystemMenu)
  bg = ButtonGadget(0, 10, 10, 200, 30, "Button")
  Debug bg ; 41945080
  Debug GadgetID(0) ; 41945080
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Last edited by BarryG on Thu Mar 05, 2020 10:04 am, edited 1 time in total.
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Get hWnd of a #PB_Any gadget?

Post by Fred »

GadgetID() always returns the handle (hWnd) for both #PB_Any and indexed mode
BarryG
Addict
Addict
Posts: 3331
Joined: Thu Apr 18, 2019 8:17 am

Re: Get hWnd of a #PB_Any gadget?

Post by BarryG »

Thanks for the info, Fred. As seen in my examples, I wasn't 100% sure because the first example returned two different things. Cheers for confirming for me so quickly!
Fred
Administrator
Administrator
Posts: 16687
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Solved] Get hWnd of a #PB_Any gadget?

Post by Fred »

#PB_Any result is a memory area holding the new PB object, which indexed result is the hWnd handle. That's history, as PB_Any has been introduced much later than indexed. It can be a bit confusing, I agree.
Post Reply