2010-08-14 10 views
5

Mi piacerebbe sapere se è possibile "WinWaitActive" per "WindowWithThisTitle" e "WindowWithThatTitle" allo stesso tempo. Sto eseguendo un comando e potrebbe esserci una finestra che mi dice che la connessione non è andata a buon fine o una finestra di dialogo utente/passaggio in arrivo.Come eseguire Winwait per due finestre contemporaneamente in AutoIt?

C'è un altro modo per farlo in questo modo?

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

Perché non desidero avere il timeout che potrebbe essere superiore a 15 secondi.

Grazie in anticipo!

+0

Molto felice di vedere domande AutoIt su StackOverflow! Non dimenticare di votare! Fare domande e rispondervi è solo una parte. – Copas

risposta

4

Che ne dici di qualcosa di simile.

$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 

Perché io non voglio avere la timeout che potrebbe essere più di 15 secondi.

WinWaitActive() non ha un timeout a meno che non ne venga specificato uno. Hai dato un timeout di cinque secondi ma potresti lasciarlo fuori e aspettare per sempre.

+0

Ma questo WhileLoop fa sì che una cpu thread/core venga eseguita al 100%. Stavo pensando a una soluzione con WinWaitActive (regex) ma non so come creare un'espressione regolare che abbia un operatore OR. Qualche idea? Cosa intendi con "Non dimenticare di votare!" btw? – MemphiZ

+0

Il sleep (5) - o più - risolverà il problema della cpu, è stato un loop difficile. WinWaitActive() non fa più bersagli e il suo ritorno è un semplice bool di successo, quindi non puoi davvero regexarlo. Hai votato una volta da quando hai iniziato a utilizzare lo stack overflow. Il sistema StackOverflow funziona davvero solo se le persone votano. Se una domanda o una risposta ti è utile, puoi votarla con la freccia su o giù con la freccia giù. Buona fortuna, spero che questo ti sia stato utile se lo avessi potuto dimostrare votando. – Copas

+0

Non ho ancora contrassegnato la risposta come risposta "THE" perché forse qualcuno conosce un metodo senza eseguire il ciclo.Aspetterò un po 'di tempo e poi lo imposterò come risposta se nessuno può fornire un modo migliore. Grazie per l'aiuto! – MemphiZ

2

È possibile utilizzare questo funzioni per due finestre ..

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

0

Sono abbastanza nuovo per AutoIt e il mondo della programmazione in generale, e ho avuto questo stesso dilemma. Per fortuna ho trovato un modo FWD dritto per farlo:

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

Quindi resterà nel ciclo finché non trova la finestra e imposta $var1 a 1. Ci sono modi probabilmente più facile (sono sicuro che gli sviluppatori boccheggiano a questo), ma questo è abbastanza semplice per me.

4

Una soluzione più semplice potrebbe essere quella di utilizzare un titolo REGEX in WinWaitActive come definito qui: http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm

Si potrebbe quindi avere qualcosa di simile:

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

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

È possibile creare un infinito ciclo while con se dichiarazioni in 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 
Problemi correlati