2010-08-14 13 views
5

Me gustaría saber si es posible "WinWaitActive" para "WindowWithThisTitle" y "WindowWithThatTitle" al mismo tiempo. Estoy ejecutando un comando y podría haber una ventana que me dice que la conexión falló o un cuadro de diálogo de usuario/pase se acerca.¿Cómo Winwait para dos ventanas simultáneamente en AutoIt?

¿Hay alguna otra manera de hacerlo así?

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

Porque no quiero tener el tiempo de espera que podría ser más de 15 segundos.

¡Gracias de antemano!

+0

¡Muy contento de ver las preguntas de AutoIt en StackOverflow! ¡No te olvides de votar! Hacer preguntas y responderlas es solo una parte. – Copas

Respuesta

4

¿Qué tal algo así?

$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 

Porque no quiero tener el tiempo de espera que podría ser más de 15 segundos .

WinWaitActive() no tiene un tiempo de espera a menos que especifique uno. Le diste un tiempo de espera de cinco segundos, pero podrías dejarlo y esperaría por siempre.

+0

Pero este WhileLoop hace que un hilo/núcleo de una CPU funcione al 100%. Estaba pensando en una solución con WinWaitActive (regex) pero no sé cómo crear una expresión regular que tenga un operador OR. ¿Alguna idea? ¿Qué quieres decir con "No olvides votar!" por cierto? – MemphiZ

+0

El sueño (5) - o más - solucionará el problema de la CPU, fue un bucle difícil. WinWaitActive() no hará múltiples objetivos y su retorno es un simple bool de éxito por lo que realmente no puede regexarlo. Has votado una vez desde que comenzaste a usar el desbordamiento de pila. El sistema StackOverflow realmente solo funciona si la gente vota. Si una pregunta o respuesta es útil para usted, puede votarla con la flecha hacia arriba o hacia abajo con la flecha hacia abajo. Buena suerte, espero que esto haya sido de ayuda si lo demostraras votando. – Copas

+0

Aún no marqué su respuesta como "LA" porque quizás alguien sepa un método sin bucles.Esperaré un tiempo y luego lo estableceré como respuesta si nadie puede proporcionar una mejor manera. ¡Gracias por tu ayuda! – MemphiZ

2

Se puede utilizar esta Funciones de dos ventanas ..

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

soy bastante nuevo en el mundo AutoIT y programación en general y tuve este mismo dilema. Por suerte me di cuenta de una manera recta fwd para hacerlo:

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

así que permanecerá en el bucle hasta que encuentra la ventana y establece $var1 a 1. Hay maneras probablemente más fácil (estoy seguro que los desarrolladores están abriendo la boca en esto) pero esto es bastante fácil para mí.

4

Una solución más simple podría ser el uso de un título de REGEX en su WinWaitActive como se define aquí: http://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm

A continuación, tendría algo como esto:

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

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

Se puede crear un bucle while con si declaraciones allí:

#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 
Cuestiones relacionadas