Enumerate easily all opened windows and gadgets

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Enumerate easily all opened windows and gadgets

Post by Flype »

I suppose that Purebasic store at runtime each opened windows, each opened gadgets (Ressource-Tracking).
So why not offer the possibility to make an easy access to this dynamic list ?

Code: Select all

EnumerateWindow(@myEnumWindow())

EnumerateGadget(WindowID(#MyWindow),@myEnumGadget())

EnumerateGadgetItem(#MyGadget,@myEnumGadgetItem())
For example :

Code: Select all

Procedure myEnumWindow(WindowID.l, WindowTitle.s)
  
  Debug WindowID
  
  SetWindowColor(WindowID,$808080)
  
  If WindowTitle = "Test"
    ProcedureReturn #False ; break the enumeration
  EndIf
  
  ProcedureReturn #True ; continue the enumeration
  
EndProcedure

Procedure myEnumGadget(GadgetID.l, GadgetText.l, GadgetState.l, GadgetType.l, GadgetData.l)
  
  Debug GadgetID
  Debug GadgetText
  Debug GadgetState
  Debug GadgetType
  Debug GadgetData
  
  Select GadgetType
    Case #PB_GadgetType_Container
      SetGadgetColor(GadgetID,#PB_Gadget_BackColor,$F0F0F0)
    Case #PB_GadgetType_Editor
      SetGadgetColor(GadgetID,#PB_Gadget_BackColor,$00FFFF)
  EndSelect
  
  ProcedureReturn #True
  
EndProcedure

Procedure myEnumGadgetItem(GadgetID.l,ItemID.l, ItemText.l, ItemState.l, ItemData.l)
  
  Debug GadgetID
  Debug ItemID
  Debug ItemText
  Debug ItemState
  Debug ItemData
  
  SetGadgetItemColor(GadgetID,ItemID,#PB_Gadget_BackColor,$E0F0E0)
  
  ProcedureReturn #True
  
EndProcedure

EnumerateWindow(@myEnumWindow())

EnumerateGadget(WindowID(#MyWindow),@myEnumGadget())

EnumerateGadgetItem(#MyGadget,@myEnumGadgetItem()) 

No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer