循环WinList()结果需要很长时间

时间:2017-09-29 11:07:21

标签: window autoit detection

我得到一个打开的窗口列表,并检查它是否包含某个标题。它工作但需要超过10秒。为什么需要这么长时间,我的代码有什么问题?

看起来WinList()不会仅列出可见的窗口。

$title = 0
$begintime = TimerInit()
MsgBox($MB_OK, "Timer", "Timer inicialized")

While $title = 0

    $aList = WinList()

    For $x = 1 To $aList[0][0]

        ;Check if a window with this title exists.
        if $aList[$x][0] = "WindowTitle" Then

            If $lastruntitle = "WindowTitle" Then

                $title = 1
                ExitLoop(2)

            Else

                SendMail4()
                $lastruntitle = "WindowTitle"
                $title = 1
                ExitLoop(2)

            EndIf

        EndIf

    Next

WEnd

1 个答案:

答案 0 :(得分:1)

您的任务的简单解决方案是:

#include <Array.au3>

While 1
   $aList = WinList()
   _ArraySearch($aList, "WindowTitle", 0, 0, 0, 0, 1, 0)
   If Not @error Then
      MsgBox(0,"","Window found!")
      Exit
   EndIf
   Sleep(100)
WEnd