|
Option Explicit
Public Declare Function EnumWindows Lib "user32" (ByVal _
lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function EnumChildWindows Lib "user32" ( _
ByVal hWndParent As Long, ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias _
"GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName _
As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString _
As String, ByVal cch As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd _
As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal _
hwnd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex _
As Long) As Long
Private Const GWL_HWNDPARENT = (-8)
Private Const GWL_STYLE = (-16)
Private Const WS_VISIBLE = &H10000000
Private Const WS_BORDER = &H800000
Public Function EnumWinProc(ByVal hwnd As Long, ByVal lParam _
As Long) As Long
If (IsWindowVisible(hwnd) Or lParam) Then
If GetParent(hwnd) = 0 Then
If GetWindowLong(hwnd, GWL_HWNDPARENT) = 0 Then
AddWndInfosToListView hwnd, lParam, _
frmEnumWindows.lvwTopLevelWnd
End If
End If
End If
EnumWinProc = True
End Function
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam _
As Long) As Long
Dim nStyle As Long
Select Case lParam
Case 0
nStyle = GetWindowLong(hwnd, GWL_STYLE)
nStyle = nStyle And (WS_VISIBLE Or WS_BORDER)
If (nStyle = (WS_VISIBLE Or WS_BORDER)) Then
AddWndInfosToListView hwnd, lParam, _
frmEnumWindows.lvwChildWnd
End If
Case 1
lParam = 0
AddWndInfosToListView hwnd, lParam, _
frmEnumWindows.lvwChildWnd
Case 2
AddWndInfosToListView hwnd, lParam, _
frmEnumWindows.lvwChildWnd
Case Else
End Select
EnumChildProc = True
End Function
Private Sub AddWndInfosToListView(ByVal hwnd As Long, ByVal _
lParam As Long, ByVal lvw As ListView)
Dim nRetVal As Long
Dim strClassName As String
Dim strWndTitle As String
Dim itmX As ListItem
strClassName = Space$(64)
nRetVal = GetClassName(hwnd, strClassName, Len(strClassName))
strClassName = Left$(strClassName, nRetVal)
nRetVal = GetWindowTextLength(hwnd)
If nRetVal > 0 Then
If nRetVal > 256 Then nRetVal = 255
strWndTitle = Space$(nRetVal + 1)
GetWindowText hwnd, strWndTitle, Len(strWndTitle)
strWndTitle = Left$(strWndTitle, nRetVal)
End If
If Len(strWndTitle) > 0 Or lParam <> 0 Then
Set itmX = lvw.ListItems.Add(Text:=strWndTitle, _
Key:=CStr(hwnd) & "h")
itmX.SubItems(1) = CStr(hwnd)
itmX.SubItems(2) = strClassName
End If
End Sub
|
|