Я знаю вот такой способ:
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetParent 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
'сам код
Public Function FindWindowByString(hWnd as Long, _
strCaption As String) As Long
Dim CurrWnd As Long
Dim Length As Long
Dim TaskName As String
Dim parent As Long
CurrWnd = GetWindow(hWnd, GW_HWNDFIRST)
While CurrWnd <> 0
parent = GetParent(CurrWnd)
Length = GetWindowTextLength(CurrWnd)
TaskName = Space$(Length + 1)
Length = GetWindowText(CurrWnd, TaskName, Length + 1)
TaskName = Left$(TaskName, Len(TaskName) - 1)
If Length > 0 Then
TaskName = LCase(TaskName)
strCaption = LCase(strCaption)
If InStr(1, TaskName, strCaption) > 0 Then
FindWindowByString = CurrWnd
Exit Function
End If
End If
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
DoEvents
Wend
End Function
Но моя программа должна 10 раз с векунду искать окно. Из-за этого ЦП загружен на 99%. Нет ли способа попроще?