문제

I would like to know if its possible to "WinWaitActive" for "WindowWithThisTitle" and "WindowWithThatTitle" at the same time. I'm executing a command and there could be a window telling me that the connection failed or a user/pass dialog coming up.

Is there another way doing it as this?

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

Because I don't want to have the timeout which could be more than 15 seconds.

Thanks in advance!

도움이 되었습니까?

해결책

How about something like this.

$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

Because I don't want to have the timeout which could be more than 15 seconds.

WinWaitActive() doesn't have a timeout unless you specify one. You gave it a five second timeout but you could leave that off and it would wait forever.

다른 팁

A simpler solution might be to use a REGEX title in your WinWaitActive as defined here : http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm

You would then have something like this:

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

If WinGetTitle($hWnd) = "WindowWithThisTitle" then
    DoSomething()
Else
    DoSomethingElse()
EndIf

You can use this Functions for two windows ..

; #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

for more with examples

I'm fairly new to autoit and the programming world in general and I had this same dilemma. Luckily I figured out a straight fwd way to do it:

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

So it'll stay in the loop until it finds the window and sets $var1 to 1. There's probably easier ways (I'm sure developers are gasping at this) but this is straight fwd enough for me.

You can create an infinite while loop with if statements in there:

#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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top