【发布时间】: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.