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

Looping through WinList() result takes much time

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

看起来 WinList() 不列出仅可见 windows。

$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

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

#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