Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim s As String
Dim t As String
s = String(1024, Chr(0))
GetWindowText hwnd, s, 1024
t = Trim(Left(s, InStr(1, s, Chr(0)) - 1))
If t <> "" Then Form1.List1.AddItem t
EnumWindowsProc = True
End Function
'以上代码须添加到模块里
Private Sub Command1_Click()
List1.Clear
Call EnumWindows(AddressOf EnumWindowsProc, 0)
Call EnumWindowsProc(GetForegroundWindow, 0)
End Sub