Date: 02-16-2022
Return to Index
created by gbSnippets
'The EnumChildWindows API, applied twice - at the parent and child window
'levels - is the basis of this code.
'Credit: Wayne Diamond
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "WIN32API.INC"
Global wList$
'// To determine if a hwnd is visible:
'IF IsWindowVisible(hWnd) = 1 THEN 'Window is visible
'// To determine the Process ID of a window:
'IF GetWindowThreadProcessId(hWnd,lProc) THEN MSGBOX "Process ID=" & STR$(lProc)
Function ParentCallback (ByVal hWndChild As Long, lRaram As Long) As Long
Dim szClass As Asciiz * %MAX_PATH
Dim szText As Asciiz * %MAX_PATH
Dim lRes As Long
lRes = GetClassName(hWndChild, szClass, SizeOf(szClass))
lRes = GetWindowText(hWndChild, szText, SizeOf(szText))
wList$ = wList$ + $CrLf + " Child: Class=" & szClass & " " & "Text=" & szText
lRes = EnumChildWindows(hWndChild, CodePtr(ChildCallback), 0&)
Function = 1
End Function
Function ChildCallback (ByVal hWndChild As Long, lRaram As Long) As Long
Dim szClass As Asciiz * %MAX_PATH
Dim szText As Asciiz * %MAX_PATH
Dim lRes As Long
lRes = GetClassName(hWndChild, szClass, SizeOf(szClass))
lRes = GetWindowText(hWndChild, szText, SizeOf(szText))
wList$ = wList$ + $CrLf + "PARENT: Class=" & szClass & " " & "Text=" & szText
Function = 1
End Function
Function PBMain As Long
On Error Resume Next
wList$ = "Enumerating all parent and child windows..."
Dim bResult As Long
bResult = EnumChildWindows(GetDesktopWindow, CodePtr(ParentCallback), 0&)
? wList
End Function
'gbs_01088
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm