7

我想知道它是否可能同时WinWaitActive进行。我正在执行一个命令,可能会有一个窗口告诉我连接失败或出现用户/密码对话框。WindowWithThisTitleWindowWithThatTitle

还有另一种方法吗?

WinWaitActive("Title1", "", 5)
If(WinExists("Title1")) Then
 MsgBox(0, "", "Do something")
Else
 If(WinExists("Title2")) Then
  MsgBox(0, "", "Do something else")
 EndIf
EndIf

因为我不想让超时时间超过 15 秒。

4

5 回答 5

8

一个更简单的解决方案可能是在您WinWaitActive定义的此处使用正则表达式标题

然后你会有这样的东西:

$hWnd = WinWaitActive("[REGEXPTITLE:(WindowWithThisTitle|WindowWithThatTitle)]")

If WinGetTitle($hWnd) = "WindowWithThisTitle" then
    DoSomething()
Else
    DoSomethingElse()
EndIf
于 2014-03-25T18:03:04.903 回答
5

这样的事情怎么样。

$stillLooking = True
While $stillLooking
    $activeWindowTitle = WinGetTitle(WinActive(""))
    If $activeWindowTitle == "Title1" Then
        MsgBox(0, "", "Do something")
        $stillLooking = False
    ElseIf $activeWindowTitle == "Title2" Then
        MsgBox(0, "", "Do something else")
        $stillLooking = False
    EndIf
    sleep(5)
WEnd

因为我不想让超时时间超过 15 秒。

WinWaitActive()除非您指定超时,否则没有超时。你给了它一个五秒的超时时间,但你可以把它关掉,它会永远等待。

于 2010-08-14T00:49:41.437 回答
2

您可以将此功能用于两个窗口..

; #FUNCTION# ====================================================================================================================
; Name...........: _2WinWait
; Description ...: Wait For Tow Windows .
; Syntax.........: _2WinWait ($FirstTitle,$SecondTitle,[$FirstText = "" ,[$SecondText = ""]] )
; Parameters ....: $FirstTitle  - Title Of First  Wondow 
;                  $SecondTitle - Title Of Second Wondow 
;                  $FirstText   - Text  Of First  Wondow 
;                  $SecondText  - Text  Of Second Wondow 
; Return values .: Success - None
;                  Failure - Returns a 0 => If Your Titles Is Wrong
; Author ........: Ashalshaikh : Ahmad Alshaikh
; Remarks .......: 
; Related .......:
; Link ..........;
; Example .......; No
; ===============================================================================================================================
Func _2WinWait ($FirstTitle,$SecondTitle,$FirstText = "" ,$SecondText = "" )
    If $FirstTitle = "" Or $SecondTitle = "" Then
        Return 0 
    Else
        Do 
        Until WinExists ($FirstTitle,$FirstText) Or WinExists ($SecondTitle,$SecondText)
    EndIf
EndFunc


; #FUNCTION# ====================================================================================================================
; Name...........: _2WinWait_Any 
; Description ...: Wait For Tow Windows And Return Any Window Id Exists .
; Syntax.........: _2WinWait_Any ($FirstTitle,$SecondTitle,[$FirstText = "" ,[$SecondText = ""]] )
; Parameters ....: $FirstTitle  - Title Of First  Wondow 
;                  $SecondTitle - Title Of Second Wondow 
;                  $FirstText   - Text  Of First  Wondow 
;                  $SecondText  - Text  Of Second Wondow 
; Return values .: Success - Number Of Window ==> 1= First Window , 2= Second Window
;                  Failure - Returns a 0 => If Your Titles Is Wrong
; Author ........: Ashalshaikh : Ahmad Alshaikh
; Remarks .......: 
; Related .......:
; Link ..........;
; Example .......; No
; ===============================================================================================================================
Func _2WinWait_Any ($FirstTitle,$SecondTitle,$FirstText = "" ,$SecondText = "" )
    If $FirstTitle = "" Or $SecondTitle = "" Then
        Return 0 
    Else
        Do 
        Until WinExists ($FirstTitle,$FirstText) Or WinExists ($SecondTitle,$SecondText)
        If WinExists ($FirstTitle,$FirstTexit) Then 
            Return 1 
        Else
            Return 2 
        EndIf
    EndIf
EndFunc

更多示例

于 2010-10-03T18:55:19.583 回答
1

总的来说,我对autoit和编程世界还很陌生,我也遇到了同样的困境。幸运的是,我想出了一个直接的方法来做到这一点:

Do
$var1 = 0
If  WinGetState("Document Reference","")    Then
    $var1 = 1
ElseIf  WinGetState("Customer Search","")   Then
    $var1 = 1
EndIf
Until $var1 = 1

所以它会一直在循环中,直到找到窗口并设置$var11. 可能有更简单的方法(我确信开发人员对此感到喘不过气来),但这对我来说已经足够了。

于 2012-02-27T18:16:25.303 回答
0

您可以在其中创建带有 if 语句的无限 while 循环:

#include <MsgBoxConstants.au3>

Example()

Func Example()
    While 1
        ; Test if the window exists and display the results.
        If WinExists("Windows Security") Then
            Local $hWnd = WinWaitActive("Windows Security", "", 2000)
            ControlSetText($hWnd, "", "[CLASS:Edit; INSTANCE:1]", "hel233")
            ControlClick("Windows Security","","[CLASS:Button; INSTANCE:2]")
            Sleep(5000)
        EndIf

        ; Test if the window exists and display the results.
        If WinExists("Spread the Word") Then
            'The line below will wait until the window is active, but we don't need that
            'Local $hWnd = WinWaitActive("Spread the Word", "", 2000)
            WinClose("Spread the Word")
            Sleep(5000)
        EndIf



    wend
EndFunc
于 2015-12-14T18:00:55.857 回答