This code lists all open windows, including hidden ones and sub-windows. Turn Debug on! Note that ListChildWindows is called recursively on each child-window, using the 'parameter' variable to track 'depth'...
General non-GUI code here...
Code: Select all
; List top-level windows' children (called by ListWindows)...
Procedure ListChildWindows (window, parameter)
GetClassName_ (window, ReAllocateMemory (0, 255), 255)
class$ = PeekS (MemoryID ())
GetWindowText_ (window, ReAllocateMemory (0, 255), 255)
title$ = PeekS (MemoryID ())
FreeMemory (0)
For a = 1 To parameter
sub$ = sub$ + "--------"
Next
Debug sub$ + ">" + Chr (34) + title$ + Chr (34) + " / Class: " + class$
EnumChildWindows_ (window, @ListChildWindows (), parameter + 1)
ProcedureReturn #TRUE
EndProcedure
; List top-level windows...
Procedure ListWindows (window, parameter)
GetClassName_ (window, ReAllocateMemory (0, 255), 255)
class$ = PeekS (MemoryID ())
GetWindowText_ (window, ReAllocateMemory (0, 255), 255)
title$ = PeekS (MemoryID ())
FreeMemory (0)
Debug ""
Debug "------------------------------------------------------------------------"
Debug Chr (34) + title$ + Chr (34) + " / Class: " + class$
Debug "------------------------------------------------------------------------"
EnumChildWindows_ (window, @ListChildWindows (), 1)
ProcedureReturn #TRUE
EndProcedure
EnumWindows_ (@ListWindows (), 0)
GUI code with tiny fix (a bit hard-coded to this tree gadget, I'm afraid)...
Code: Select all
#TREEGADGET = 0
Procedure ListChildWindows (window, parameter)
GetClassName_ (window, ReAllocateMemory (0, 255), 255)
class$ = PeekS (MemoryID ())
GetWindowText_ (window, ReAllocateMemory (0, 255), 255)
title$ = PeekS (MemoryID ())
If title$ = ""
title$ = "[Unnamed]"
EndIf
FreeMemory (0)
OpenTreeGadgetNode (#TREEGADGET)
AddGadgetItem (#TREEGADGET, -1, title$ + " [" + class$ + "]")
EnumChildWindows_ (window, @ListChildWindows (), 0)
CloseTreeGadgetNode (#TREEGADGET)
ProcedureReturn #TRUE
EndProcedure
Procedure ListWindows (window, parameter)
GetClassName_ (window, ReAllocateMemory (0, 255), 255)
class$ = PeekS (MemoryID ())
GetWindowText_ (window, ReAllocateMemory (0, 255), 255)
title$ = PeekS (MemoryID ())
If title$ = ""
title$ = "[Unnamed]"
EndIf
FreeMemory (0)
OpenTreeGadgetNode (#TREEGADGET)
AddGadgetItem (#TREEGADGET, -1, title$ + " [" + class$ + "]")
EnumChildWindows_ (window, @ListChildWindows (), 1)
CloseTreeGadgetNode (#TREEGADGET)
ProcedureReturn #TRUE
EndProcedure
Procedure WinHook (WindowID, Message, wParam, lParam)
If Message = #WM_SIZE
ResizeGadget (#TREEGADGET, 0, 0, WindowWidth (), WindowHeight () - 25)
RedrawWindow_ (GadgetID (#TREEGADGET), #NULL, #NULL, #RDW_INVALIDATE)
ResizeGadget (1, 0, WindowHeight () - 25, WindowWidth (), 25)
EndIf
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure GetWindowTree ()
ClearGadgetItemList (#TREEGADGET)
OpenTreeGadgetNode (#TREEGADGET)
AddGadgetItem (#TREEGADGET, -1, "All windows...")
EnumWindows_ (@ListWindows (), 0)
CloseTreeGadgetNode (#TREEGADGET)
EndProcedure
OpenWindow (0, 0, 0, 400, 300, #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget, "All windows...")
CreateGadgetList (WindowID ())
TreeGadget (#TREEGADGET, 0, 0, WindowWidth (), WindowHeight () - 25)
GetWindowTree ()
SetGadgetItemState (0, 0, #PB_Tree_Expanded)
ButtonGadget (1, 0, WindowHeight () - 25, WindowWidth (), 25, "Update list...")
SetWindowCallback (@WinHook ())
Repeat
Select WaitWindowEvent ()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
If EventGadgetID () = 1
GetWindowTree ()
SetGadgetItemState (0, 0, #PB_Tree_Expanded)
EndIf
EndSelect
ForEver