Option Explicit
Private Declare Function GetTopWindow Lib "user32" (ByVal hwnd As Long) _
As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" _
(ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Declare Function GetParent 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 Declare Function IsWindowVisible Lib "user32" _
(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 GetClassName Lib "user32" Alias _
"GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GWL_STYLE = (-16)
Private Const GWL_HWNDPARENT = (-8)
Private Const WS_OVERLAPPED = &H0&
Private Const WS_BORDER = &H800000
Private Const WS_DLGFRAME = &H400000
Private Const WS_CAPTION = WS_BORDER Or WS_DLGFRAME
Private Const WS_SYSMENU = &H80000
Private Const WS_THICKFRAME = &H40000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED Or _
WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or _
WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
' Return information about this window.
Private Sub GetWindowInfo(ByVal app_hwnd As Long, _
ByRef app_parent As Long, ByRef app_owner As Long, _
ByRef app_visible As Boolean, ByRef app_style As Long, _
ByRef app_text As String, ByRef app_class As String)
Const MAX_LENGTH = 1024
Dim buf As String * MAX_LENGTH
Dim length As Long
app_parent = GetParent(app_hwnd)
app_owner = GetWindowLong(app_hwnd, GWL_HWNDPARENT)
app_visible = IsWindowVisible(app_hwnd)
app_style = GetWindowLong(app_hwnd, GWL_STYLE)
length = GetWindowText(app_hwnd, buf, MAX_LENGTH)
app_text = Left$(buf, length)
length = GetClassName(app_hwnd, buf, MAX_LENGTH)
app_class = Left$(buf, length)
End Sub
Private Sub Form_Load()
Dim app_hwnd As Long
Dim app_parent As Long
Dim app_owner As Long
Dim app_visible As Boolean
Dim app_style As Long
Dim app_text As String
Dim app_class As String
app_hwnd = GetTopWindow(0)
Do While app_hwnd <> 0
' Get information about this window.
GetWindowInfo app_hwnd, app_parent, app_owner, _
app_visible, app_style, app_text, app_class
' See if this window is interesting.
If app_visible And _
app_parent = 0 And _
app_owner = 0 And _
Len(app_text) > 0 And _
Left$(app_text, 8) <> "VBBubble" And _
(Left$(app_class, 7) <> "Progman" Or _
(app_style And WS_OVERLAPPEDWINDOW) <> 0) _
Then
List1.AddItem app_class & " - " & app_text
End If
app_hwnd = GetNextWindow(app_hwnd, GW_HWNDNEXT)
Loop
End Sub