I recently got this working myself, its more complex than I thought it would be...
In a module :
VB Code:
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim lReturn As Long
Dim lExStyle As Long
Dim bNoOwner As Boolean
Dim sWindowText As String
Dim sWin As String
'
' This callback function is called by Windows (from
' the EnumWindows API call) for EVERY window that exists.
' It populates the combobox with a list of windows that we
' are interested in.
'
' Windows to display are those that:
' - are not this app's
' - are visible
' - do not have a parent
' - have no owner and are not Tool windows OR
' have an owner and are App windows
'
sWin = Space$(256)
sWin = GetClassName(hwnd, sWin, Len(sWin))
If IsWindowVisible(hwnd) Then
If GetParent(hwnd) = 0 Then
bNoOwner = (GetWindow(hwnd, GW_OWNER) = 0)
lExStyle = GetWindowLong(hwnd, GWL_EXSTYLE)
If (((lExStyle And WS_EX_TOOLWINDOW) = 0) And bNoOwner) Or _
((lExStyle And WS_EX_APPWINDOW) And Not bNoOwner) Then
'
' Get the window's caption.
'
sWindowText = Space$(256)
lReturn = GetWindowText(hwnd, sWindowText, Len(sWindowText))
If lReturn Then
'
' Add it to our list.
'
WindCount = WindCount + 1
sWindowText = Left$(sWindowText, lReturn)
frmFindWindow.cboWindows.AddItem sWindowText
End If
End If
End If
End If
EnumWindowsProc = True
End Function
In your form :
VB Code:
Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Call EnumWindows(AddressOf EnumWindowsProc, frmFindWindow.cboWindows.hwnd)