| 
    
     |  | こんばんは 
 済みません、コードの間違いも修正しました。
 
 'API宣言部
 Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
 Public Declare Function IsWindowVisible Lib "user32" (ByVal hWnd 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 GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
 '定数、変数
 Public Const GW_OWNER = 4
 Public flg As Boolean
 '再帰処理用コールバック関数
 Public Function GetProc(ByVal hWnd As Long, lParam As Long) As Boolean
 Dim sName As String * 128
 Dim ret  As Long
 
 sName = ""
 'キャプションを取得
 ret = GetWindowText(hWnd, sName, Len(sName))
 '可視状態のウィンドウを調べる
 If IsWindowVisible(hWnd) Then
 'オーナーフォームのハンドル取得
 If GetWindow(hWnd, GW_OWNER) = 0 Then
 If ret <> 0 Then
 '判定するアプリケーションのキャプション名
 If sName Like "対象のWindowキャプション名*" Then
 '見つかったらフラグをTrueにして、関数から抜ける
 flg = True
 Exit Function
 End If
 End If
 End If
 End If
 GetProc = True
 End Function
 
 
 Sub test()
 Dim s As Single
 s = Timer
 flg = False
 Do
 Call EnumWindows(AddressOf GetProc, 0)
 'フラグがTrueになる前に10秒経過したらループ抜ける
 If Timer - s > 10 Then '10秒待ち
 Exit Do
 End If
 Loop Until flg = True
 '見つかったらフラグはTrue、時間切れならFalse
 If flg = False Then
 MsgBox "時間切れ、見つかりません"
 Else
 '見つかったので次の処理
 Stop
 End If
 End Sub
 
 
 |  |