Restored from previous forum. Originally posted by fweil.
From Beginners section discussion I place this snippet here (also available soon on ressource site).
Any feedback will be welcome.
Krgds
Code: Select all
;======================================================
;
; EnumWindows TreeView
; F.Weil 20020828
;
; Two linked lists are used for both parent windows and children objects
;
; Each list is updated using a callback Enum procedure
;
; The Tree gadget is build when opening the program's main window
; then you have just to click the items / nodes and surf.
;
; This program has a resizing feature linking the tree gadget size to the main window.
;
; I choosed to put all handle, text and class name information in a single label in the
; tree gadget for each item, so that no more action is necessary except looking labels.
;
; I also tried a List icon gadget version of this program but this tree gadget version is
; really simple and convenient for any further feature to add later.
;
; Feel free to modify update this code sample for any use in the PureBasic community.
;
Structure FindWindowData
hFW.l ; variable to store a handle
sFW.s ; variable to store a Window name
cFW.s ; variable to store a window class name
EndStructure
Global NewList FindWindow.FindWindowData()
Global NewList FindChild.FindWindowData()
Procedure.l EnumChildProc(hChild, lParam)
ChildName.s = Space(255)
ChildClass.s = Space(255)
If GetWindowText_(hChild, ChildName, 255)
Else
SendMessage_(hChild, #WM_GETTEXT, 500, ChildName)
EndIf
If GetClassName_(hChild, ChildClass, 255)
AddElement(FindChild())
FindChild()\hFW = hChild
FindChild()\sFW = ChildName
FindChild()\cFW = ChildClass
EndIf
ProcedureReturn 1
EndProcedure
Procedure.l EnumWindowsProc(hFind, lParam)
WindowName.s = Space(255)
WindowClass.s = Space(255)
If GetWindowText_(hFind, WindowName, 255)
Result = GetClassName_(hFind, WindowClass, 255)
AddElement(FindWindow())
FindWindow()\hFW = hFind
FindWindow()\sFW = WindowName
FindWindow()\cFW = WindowClass
EndIf
ProcedureReturn 1
EndProcedure
;
; Main starts here
;
WEvent.l
WindowXSize.l
WindowYSize.l
Quit.l
Quit = #False
WindowXSize = 320
WindowYSize = 240
If OpenWindow(0, 200, 200, WindowXSize, WindowYSize, "MyWindow", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar)
TreeGadget(100, 0, 0, WindowXSize, WindowYSize, #PB_Tree_AlwaysShowSelection)
If EnumWindows_(@EnumWindowsProc(), 0)
ResetList(FindWindow())
While NextElement(FindWindow())
AddGadgetItem(100, -1, FindWindow()\sFW + " - " + FindWindow()\cFW + " - " + Str(FindWindow()\hFW))
ClearList(FindChild())
If EnumChildWindows_(FindWindow()\hFW, @EnumChildProc(), 0)
ResetList(FindChild())
While NextElement(FindChild())
AddGadgetItem(100, -1, FindChild()\sFW + " - " + FindChild()\cFW + " - " + Str(FindChild()\hFW))
Wend
EndIf
Wend
EndIf
Repeat
WEvent = WaitWindowEvent()
Select WEvent
Case #PB_Event_CloseWindow
Quit = #True
Default
EndSelect
If WindowXSize <> WindowWidth(0) Or WindowYSize <> WindowHeight(0)
WindowXSize = WindowWidth(0)
WindowYSize = WindowHeight(0)
ResizeGadget(100, 0, 0, WindowXSize, WindowYSize)
EndIf
Until Quit
EndIf
End
;======================================================
14, rue Douer
F64100 Bayonne