VB中callbacke function 如下:
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim slength As Long, WndTitle As String ' title bar text length and buffer
Dim retval As Long ' return value
Dim WClass As String * 50
Static winnum As Integer ' counter keeps track of how many windows have been enumerated
winnum = winnum + 1 ' one more window enumerated....
slength = GetWindowTextLength(hwnd) + 1 ' get length of title bar text
WndTitle = Space(slength) ' make room in the buffer
retval = GetWindowText(hwnd, WndTitle, slength) ' get title bar text GetClassName hwnd, WClass, 50
EnumChildProc = 1 ' return value of 1 means continue enumeration
End Function结果列表在excel中,窗口句柄为66622的类可以找到,但是Title却为空
ChildWndHnd ChildWndClass ChildWndTitle
66624 TCoolBar
66626 TToolBar
66620 TCoolBar
66622 TToolBar
66618 TPanel但是为什么SPY++中却可以找到:
Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim slength As Long, WndTitle As String ' title bar text length and buffer
Dim retval As Long ' return value
Dim WClass As String * 50
Static winnum As Integer ' counter keeps track of how many windows have been enumerated
winnum = winnum + 1 ' one more window enumerated....
slength = GetWindowTextLength(hwnd) + 1 ' get length of title bar text
WndTitle = Space(slength) ' make room in the buffer
retval = GetWindowText(hwnd, WndTitle, slength) ' get title bar text GetClassName hwnd, WClass, 50
EnumChildProc = 1 ' return value of 1 means continue enumeration
End Function结果列表在excel中,窗口句柄为66622的类可以找到,但是Title却为空
ChildWndHnd ChildWndClass ChildWndTitle
66624 TCoolBar
66626 TToolBar
66620 TCoolBar
66622 TToolBar
66618 TPanel但是为什么SPY++中却可以找到:
Option ExplicitPrivate Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Declare Function EnumChildWindows Lib "user32.dll" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As LongPublic Function EnumChildProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim slength As Long, WndTitle As String ' title bar text length and buffer
Dim retval As Long ' return value
Dim WClass As String * 256
'Static winnum As Integer ' counter keeps track of how many windows have been enumerated
'winnum = winnum + 1 ' one more window enumerated....
slength = GetWindowTextLength(hWnd) + 1 ' get length of title bar text
WndTitle = Space(slength) ' make room in the buffer
retval = GetWindowText(hWnd, WndTitle, slength) ' get title bar text
Call GetClassName(hWnd, WClass, 256)
WClass = Left(WClass, InStr(WClass, Chr(0)) - 1)
Form1.List1.AddItem hWnd & " 标题:" & WndTitle
Form1.List2.AddItem hWnd & " 类名:" & WClass
EnumChildProc = 1 ' return value of 1 means continue enumeration
End Function'窗体模块
Option ExplicitPrivate Sub Command1_Click()
EnumWindows AddressOf EnumChildProc, ByVal 0&
End Sub