自动如何检查窗口是否出现和关闭

时间:2015-11-11 11:20:52

标签: window autoit

如何检查特定窗口是否出现在自动。

目前我使用Auto it Adob​​e After Effects运行, 到目前为止一切顺利。

问题是如果用户没有安装快速时间,则会弹出警告消息。

现在我想检查该窗口是否显示并处于活动状态,然后将其关闭。

到目前为止,我有这个,但没有奏效:

    Local $iPID = Run("C:\Program Files\Adobe\Adobe After Effects CC 2015\Support Files\AfterFX.exe", "", @SW_SHOWMAXIMIZED)

    WinWait("[CLASS:AfterEffects]", "", 1000)

    Sleep(200000)

   ; if qicktime warning eror appears
   If WinExists ("DroverLord - Window Class", "") Then
      Send ("{ENTER}")
   EndIf

2 个答案:

答案 0 :(得分:1)

这有帮助吗?

Opt("WinDetectHiddenText", 1) ;0=don't detect, 1=do detect
Opt("WinSearchChildren", 1) ;0=no, 1=search children also
Opt("WinTextMatchMode", 1) ;1=complete, 2=quick
Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase

#include<Date.au3>

Local $iPID = Run("C:\Program Files\Adobe\Adobe After Effects CC 2015\Support Files\AfterFX.exe", "", @SW_SHOWMAXIMIZED)
If @error Then
    ConsoleWrite('ERROR' & @CRLF)
    Exit(0)
EndIf

Global $end = False
Do
    ; if qicktime warning eror appears
    If WinExists("DroverLord - Window Class", "") Then
        ConsoleWrite('!FOUND ' & _NowTime() & @CRLF)
        Send("{ENTER}") ;close?
        WinClose("DroverLord - Window Class", "") ; this
        WinKill("DroverLord - Window Class", "") ; or this
        $end = True
    EndIf
Until $end

答案 1 :(得分:0)

以下是您要尝试执行的一些示例代码:

Local $fDiff
Local $sAfterFXPath = "C:\Program Files\Adobe\Adobe After Effects CC 2015\Support Files\AfterFX.exe"

If FileExists($sAfterFXPath) Then
    Local $iPID = Run($sAfterFXPath, "", @SW_SHOWMAXIMIZED)

;no need to call WinExists becuase you are waiting for it to exist and be active with WinActivate

Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.

Do
    $fDiff = TimerDiff($hTimer)
Until WinActive("Title you are looking for") Or $fDiff >= 30000 ;<<<will exit loop when the window is active or after 30 seconds

If WinActive("Title you are looking for") Then
    ;Closes the window now that it is active
    WinClose("Title you are looking for")
Else
    MsgBox(0, "", "The window was never active.")
EndIf
Else
   MsgBox(0, "", "File path not found. Do something else...")
EndIf