Page 1 of 1

[Solved] Get hWnd of a #PB_Any gadget?

Posted: Thu Mar 05, 2020 10:00 am
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

Re: Get hWnd of a #PB_Any gadget?

Posted: Thu Mar 05, 2020 10:02 am
by Fred
GadgetID() always returns the handle (hWnd) for both #PB_Any and indexed mode

Re: Get hWnd of a #PB_Any gadget?

Posted: Thu Mar 05, 2020 10:04 am
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!

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

Posted: Thu Mar 05, 2020 10:07 am
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.