Hi Tom,
I found the following function whilst searching on the net, no idea if
it works but it is designed as a substitute for what you are after,
-------------------------------------------------------------------
Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, _
ByVal wCmd 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 GetClassName Lib "user32" _
Alias "GetClassNameA" _
(ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDLAST = 1
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDPREV = 3
Public Const GW_OWNER = 4
Public Const GW_CHILD = 5
Form code:
Option Explicit
Private Sub cmdStart_Click()
'Used to return window handles.
Dim TitleToFind As String, ClassToFind As String
List1.Clear
'Set the FindWindowLike text values from
'the strings entered into the textboxes
TitleToFind = (txtTitle) & "*"
ClassToFind = (txtClass)
Call FindWindowLike(0, TitleToFind, ClassToFind)
lbCount = CStr(List1.ListCount) & " matches found"
End Sub
Private Function FindWindowLike(ByVal hWndStart As Long, _
WindowText As String, _
Classname As String) As Long
Dim hwnd As Long
Dim sWindowText As String
Dim sClassname As String
Dim r As Long
'Hold the level of recursion and
'hold the number of matching windows
Static level As Integer
'Initialize if necessary. This is only executed
'when level = 0 and hWndStart = 0, normally
'only on the first call to the routine.
If level = 0 Then
If hWndStart = 0 Then hWndStart = GetDesktopWindow()
End If
'Increase recursion counter
level = level + 1
'Get first child window
hwnd = GetWindow(hWndStart, GW_CHILD)
Do Until hwnd = 0
'Search children by recursion
Call FindWindowLike(hwnd, WindowText, Classname)
'Get the window text and class name
sWindowText = Space$(255)
r = GetWindowText(hwnd, sWindowText, 255)
sWindowText = Left(sWindowText, r)
sClassname = Space$(255)
r = GetClassName(hwnd, sClassname, 255)
sClassname = Left(sClassname, r)
'Check if window found matches the search parameters
If (sWindowText Like WindowText) And _
(sClassname Like Classname) Then
List1.AddItem hwnd & vbTab & _
sClassname & vbTab & _
sWindowText
FindWindowLike = hwnd
'uncommenting the next line causes the routine to
'only return the first matching window.
'Exit Do
End If
'Get next child window
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
'Reduce the recursion counter
level = level - 1
End Function