【问题标题】:Looping through WinList() result takes much time循环遍历 WinList() 结果需要很长时间
【发布时间】:2017-09-29 11:07:20
【问题描述】:

我得到一个打开的窗口列表并检查它是否包含某个标题。它正在工作,但需要超过 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

【问题讨论】:

  • 您是在脚本启动后打开必要的窗口还是在启动时已经打开的窗口?如果你真的需要使用While循环,你必须添加一些sleep至少sleep(100),否则两次cpu会过载。同时显示 SendMail4() 函数。
  • "为什么要花这么长时间,我的代码有什么问题?" 使用WinExists()WinGetHandle() 检查窗口是否存在。 Related.

标签: window autoit detection


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 2015-03-30
    • 1970-01-01
    相关资源
    最近更新 更多