Private Declare Function GetDesktopWindow Lib 'user32' () As Long
Private Declare Function GetWindow Lib 'user32' (ByVal hwnd As Long, ByVal _
wCmd 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 Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Sub Form_Load()
Dim dhwnd As Long, hwnd As Long, wc As Long, rval As Long
Dim wname As String, index As Long
dhwnd = GetDesktopWindow()
hwnd = GetWindow(dhwnd, GW_CHILD)
wc = 1: index = 0
Do While hwnd <> 0
wname = Space(260)
rval = GetWindowText(hwnd, wname, 260)
wname = Left(wname, InStr(wname, Chr(0)) - 1)
If Len(wname) Then
'MsgBox wname
List1.AddItem wname, index
index = index + 1
End If
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
Label1.Caption = 'Total number of Open Windows = ' & index + 1
End Sub