Comment Winwait pour deux fenêtres simultanément dans AutoIt?

Je voudrais savoir s’il est possible de “WinWaitActive” pour “WindowWithThisTitle” et “WindowWithThatTitle” en même temps. J’exécute une commande et il peut y avoir une fenêtre indiquant que la connexion a échoué ou qu’une boîte de dialog utilisateur / passe est apparue.

Y a-t-il une autre façon de le faire comme ça?

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

Parce que je ne veux pas avoir le délai qui pourrait dépasser 15 secondes.

Merci d’avance!

    Que diriez-vous quelque chose comme ça.

     $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 

    Parce que je ne veux pas avoir le délai qui pourrait dépasser 15 secondes.

    WinWaitActive () n’a pas de délai d’attente, sauf si vous en spécifiez un. Vous lui avez accordé un délai de cinq secondes, mais vous pouviez le laisser et il attendrait pour toujours.

    Une solution plus simple pourrait consister à utiliser un titre REGEX dans votre WinWaitActive tel que défini ici: http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm

    Vous auriez alors quelque chose comme ceci:

     $hWnd = WinWaitActive("[REGEXPTITLE:(WindowWithThisTitle|WindowWithThatTitle)]") If WinGetTitle($hWnd) = "WindowWithThisTitle" then DoSomething() Else DoSomethingElse() EndIf 

    Vous pouvez utiliser cette fonction pour deux fenêtres.

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

    pour plus avec des exemples

    Je suis assez nouveau pour autoit et le monde de la programmation en général et j’ai eu le même dilemme. Heureusement, j’ai trouvé un moyen simple de le faire:

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

    Donc, il restra dans la boucle jusqu’à ce qu’il trouve la fenêtre et $var1 à 1. Il y a probablement des moyens plus faciles (je suis sûr que les développeurs sont à la peine) mais c’est assez simple pour moi.

    Vous pouvez créer une boucle while infinie avec les instructions if qui s’y trouvent:

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