Page 1 of 1

Get Current Gadget List Window Number (Windows only)

Posted: Thu Jan 14, 2016 5:17 am
by TI-994A
In response to a recent forum post, this GadgetListWindow() function translates the window ID, obtained from calling UseGadgetList(0), to its PureBasic window number:

* adapted from GetParent()

Code: Select all

;========================================================
; GadgetListWindow() returns the window number of the
; current gadget list obtained from UseGadgetList(0)
;
; Windows only
;   
; tested & working on Win 8.1 with PureBasic v5.40 (x64)
;
; by TI-994A - free to use, improve, share...
;
; 14th January 2016
;========================================================

Procedure GadgetListWindow()
  ;usig the UseGadgetList(0) function, the 
  ;GetProp_() function translates the returned
  ;PureBasic window ID to its window number
  w = GetProp_(UseGadgetList(0), 
      StringField("PB_WINDOWID", 1, ",")) - 1
  ProcedureReturn w
EndProcedure

OpenWindow(0, 100, 100, 200, 100, "Window 0")
ButtonGadget(0, 10, 20, 100, 30, "Button")
OpenWindow(1, 200, 200, 200, 100, "Window 1")
ButtonGadget(1, 10, 20, 100, 30, "Button")
OpenWindow(2, 300, 300, 200, 100, "Window 2")
ButtonGadget(2, 10, 20, 100, 30, "Button")

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      appQuit = 1
      
    Case #PB_Event_Gadget
      ;for this example, when a button is pressed, 
      ;its window is made the current gadget list
      UseGadgetList(WindowID(EventWindow()))
      MessageRequester("UseGadgetList()", 
                       "Current gadget list: Window #" + 
                       Str(GadgetListWindow()))
  EndSelect
Until appQuit = 1
May be useful. :)