Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
%IDC_ListView = 500
Type WindowList
hwnd As Dword
PARENT As Long
R As RECT
End Type
Global hDlg As Dword, iCount, iResult As Long
Global szTesxt, szClass, szParentClass As Asciiz * %MAX_PATH
Global wList() As WindowList
Function PBMain() As Long
ReDim wList(5000)
Dialog New Pixels, 0, "Enumerate Windows",300,300,800,500,%WS_OverlappedWindow To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local iResult As Long
Select Case Cb.Msg
Case %WM_InitDialog
CreateListView
iResult = EnumWindows(CodePtr(ParentCallback), 0&)
ReDim Preserve wList(iCount)
FillListView
' ListView Sort hDlg, %IDC_ListView, 1, Descend
Dialog Set Text hDlg, "Enumerate Windows: " + Str$(iCount) + " found"
Case %WM_Size
Control Set Size hDlg, %IDC_ListView, Lo(Word,Cb.LParam)-20, Hi(Word,Cb.LParam)-20
End Select
End Function
Function ParentCallback (ByVal hWndChild As Long, lRaram As Long) As Long
Local szParentClass as Asciiz * %Max_Path
iResult = GetClassName(hWndChild, szParentClass, SizeOf(szParentClass))
Incr iCount
wList(iCount).Parent = 1
wList(iCount).hWnd = hWndChild
Select Case szParentClass
Case "COMBOBOX", "COMBOBOXEX32", "SYSIPADDRESS32", "SYSLISTVIEW32", "SYSTABCONTROL32", "SYSDATATIMEPICK32"
'do nothing
Case Else
If IsWindowVisible(hWndChild) Then
iResult = EnumChildWindows(hWndChild, CodePtr(ChildCallback), 0&)
End If
End Select
Function = 1
End Function
Function ChildCallback (ByVal hWndChild As Long, lRaram As Long) As Long
Incr iCount
wList(iCount).hWnd = hWndChild
Function = 1
End Function
Sub CreateListView
'create control
Control Add ListView, hDlg, %IDC_ListView, "", 10,10,175,75 '225
'columns hdlg, id&, col, "test", width, format
ListView Insert Column hDlg, %IDC_ListView, 1, "#", 50, 0
ListView Insert Column hDlg, %IDC_ListView, 2, "hWnd", 75, 0
ListView Insert Column hDlg, %IDC_ListView, 3, "Level", 200, 0
ListView Insert Column hDlg, %IDC_ListView, 4, "Class", 200, 0
ListView Insert Column hDlg, %IDC_ListView, 5, "Text", 100, 0
ListView Insert Column hDlg, %IDC_ListView, 6, "x1", 50, 0
ListView Insert Column hDlg, %IDC_ListView, 7, "y1", 50, 0
ListView Insert Column hDlg, %IDC_ListView, 8, "x2", 50, 0
ListView Insert Column hDlg, %IDC_ListView, 9, "y2", 50, 0
ListView Set StyleXX hDlg, %IDC_ListView, %LVS_Ex_GridLines Or %LVS_Ex_FullRowSelect
ListView Set StyleXX hDlg, %IDC_ListView, %LVS_Ex_FullRowSelect
End Sub
Sub FillListview
Local i, iResult As Long
Local szClass, szText As Asciiz * %MAX_PATH
For i = 0 To UBound(wList)
iResult = GetWindowRect(wList(i).hWnd, wList(i).R) 'save bounding dimensions
iResult = GetClassName(wList(i).hwnd, szClass, SizeOf(szClass))
iResult = GetWindowText(wList(i).hwnd, szText, SizeOf(szText))
'rows hdlg, id&, row, image, "text"
ListView Insert Item hDlg, %IDC_ListView, i, 0, Str$(i)
' 'items hdlg, id&, row, col, "text"
ListView Set Text hDlg, %IDC_ListView, i,2, Str$(wList(i).hwnd)
ListView Set Text hDlg, %IDC_ListView, i,3, IIf$(wList(i).Parent,"Parent:"," Child:")
ListView Set Text hDlg, %IDC_ListView, i,4, szClass
ListView Set Text hDlg, %IDC_ListView, i,5, szText
ListView Set Text hDlg, %IDC_ListView, i,6, Str$(wList(i).R.nLeft)
ListView Set Text hDlg, %IDC_ListView, i,7, Str$(wList(i).R.nTop)
ListView Set Text hDlg, %IDC_ListView, i,8, Str$(wList(i).R.nRight)
ListView Set Text hDlg, %IDC_ListView, i,9, Str$(wList(i).R.nBottom)
Next i
End Sub
'gbs_01091
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm