Question

Je voudrais savoir s'il est possible de « WinWaitActive » pour « WindowWithThisTitle » et « WindowWithThatTitle » en même temps. J'exécute une commande et il pourrait y avoir une fenêtre me disant que la connexion a échoué ou un utilisateur / pass dialogue à venir.

Y at-il une autre façon de le faire comme cela?

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 être plus de 15 secondes.

Merci à l'avance!

Était-ce utile?

La solution

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 la   délai qui pourrait être plus de 15   secondes.

WinWaitActive () ne dispose pas d'un délai d'attente sauf si vous spécifiez un. Vous avez donné cinq secondes délai d'attente, mais vous pouvez laisser ce hors et qu'elle attendrait toujours.

Autres conseils

Une solution plus simple est peut-être 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 ces fonctions 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 d'exemples

Je suis assez nouveau pour AutoIt et le monde de la programmation en général et j'ai eu ce même dilemme. Heureusement, je me suis trouvé un moyen de droit fwd de le faire:

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

Il va rester dans la boucle jusqu'à ce qu'il trouve la fenêtre et ensembles $var1 à 1. Il y a des moyens probablement plus facile (je suis sûr que les développeurs sont haletant à ce sujet), mais cela suffit fwd tout droit vers moi.

Vous pouvez créer un infini en boucle avec des instructions if là:

#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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top