Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long'该函数是EnumWindows的回调函数,EnumWindows函数将遍历的窗口句柄传递到hwnd参数中 Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long Dim astr As String * 256 Dim l As Long
l = GetWindowText(hwnd, astr, Len(astr)) '得到窗口的标题 If InStr(astr, " ") > 1 Then Form1.List1.AddItem astr End If EnumWindowsProc = True End FunctionPrivate Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long l = EnumWindows(AddressOf EnumWindowsProc, 0)
Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim astr As String * 256
Dim l As Long
l = GetWindowText(hwnd, astr, Len(astr)) '得到窗口的标题
If InStr(astr, " ") > 1 Then
Form1.List1.AddItem astr
End If
EnumWindowsProc = True
End FunctionPrivate Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long l = EnumWindows(AddressOf EnumWindowsProc, 0)