Private Declare Function GetWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function IsWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
Private Const GW_HWNDFIRST As Long = 0
Private Const GW_HWNDNEXT As Long = 2
Схема такая же как при любых других перечислениях:
GetWindow твоё окно,gw_first
do
GetWindText
if left$(,13)=="asdfsd" then
end if
GetWindow след. окно, gw_next
loop
А чтобы потом проверить есть ли оно или уже исчезло, я бы юзал IsWindow, хотя можно использовать любую функцию, требующую описатель окна - один фиг с ошибкой завершится...
Это так схематично, т.к. готового кода у меня нет, а те куски что есть один фиг надо затачивать под твою задачу, т.к. по заголовку окон я как правило не ищу - гораздо эффективнее их искать по имени класса.
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Dim sArray() As String
Private Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
On Local Error GoTo er
EnumWindowsProc = vbNull
Exit Function
er:
ReDim sArray(0)
Resume Next
End Function
Public Function GetWindowsByTitle(ByVal sTitle As String, ByRef outArray() As Long) As Long
On Local Error GoTo er
Dim i As Long
Call EnumWindows(AddressOf EnumWindowsProc, 0&
For i = 0 To UBound(sArray)
If Left$(sArray(i), Len(sTitle)) = sTitle Then
ReDim Preserve outArray(UBound(outArray) + vbNull)
outArray(UBound(outArray)) = VBA.Val(Split(sArray(UBound(outArray)), ";"(1))
GetWindowsByTitle = GetWindowsByTitle + vbNull
End If
Next
Erase sArray
Exit Function
er:
ReDim outArray(0)
Resume Next
End Function
Использование в форме:
Option Explicit
Private Sub Form_Load()
Dim arr() As Long
Dim cnt As Long
cnt = GetWindowsByTitle("Project", arr)
For cnt = 0 To cnt
Debug.Print arr(cnt)
Next
End Sub