Get Current Gadget List Window Number (Windows only)

Share your advanced PureBasic knowledge/code with the community.
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Get Current Gadget List Window Number (Windows only)

Post 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. :)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D