Private Sub Command1_Click()
If Val(Text1.Text) <> 0 Then '如果输入的父句柄不等于零
List1.Clear
EnumChildWindows Text1.Text, AddressOf abc, ByVal 0& '参数abc为模块中的地址
End If
End Sub
'----------------------以上是窗体代码----------------------
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpclassname As String, ByVal nMaxCount As Long) As Long
'-----------------------------声名取类名API
Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
'-----------------------------声名枚举子句柄API
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
'-----------------------------声名取标题API
Public Function abc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim leiming As String * 50 '声名字符串变量,大小为50
Dim biaoti As String * 100 '声名字符串变量,大小为100
GetClassName hwnd, leiming, 50 '取类名
GetWindowText hwnd, biaoti, 100 '取标题
If InStr(leiming, Chr(0)) > 0 Then '如类名中有特殊符号vbNullChar
leiming = Replace(leiming, Chr(0), "") '则替换特殊符号vbNullChar为""
End If
If InStr(biaoti, Chr(0)) > 0 Then '如果标题中有特殊符号vbNullChar
biaoti = Replace(biaoti, Chr(0), "") '则替换特殊符号vbNullChar为""
End If
Form1.List1.AddItem hwnd & " , " & leiming & " , " & biaoti '分别把句柄,类名,标题加载到list1
abc = 1 '这个参数不晓得是什么怪物
End Function
'----------------------以上是标准模块代码----------------------