StatusBarWait


等待一个窗口的状态栏包含指定的字符串.

StatusBarWait [, BarText, Seconds, Part#, WinTitle, WinText, Interval, ExcludeTitle, ExcludeText]

参数

BarText

命令所等待出现的文本或部分文本. 默认值是空的, 这意味着等待目标状态栏变成空的. 该文本是大小写敏感的同时匹配行为由 SetTitleMatchMode 决定, 和下面的 WinTitle 类似.

代替等待状态栏的文本 改变 的方法, 在循环中使用 StatusBarGetText, 或者像页面底部的例子那样使用 RegEx.

Seconds 在超时前等待的秒数 (可以包含小数点或者是一个 表达式), 超时后 ErrorLevel 将被设置为 1. 默认值为空, 这意味着无限期等待. 指定为 0 则等同于 0.5.
Part# 希望获取文本的状态栏那一部分的数字, 可以是一个 表达式.默认值为 1, 这部分通常包含了我们感兴趣的文本.
WinTitle 目标窗口的标题或标题中的部分文字 (匹配模式由 SetTitleMatchMode 决定).如果省略所有的参数, 默认目标是 上一次匹配窗口.如果此参数是字母 A, 同时省略其他三个窗口参数, 则以当前的活动窗口为目标.要用窗口的类名进行匹配, 请指定 ahk_class ExactClassName (Window Spy 中可以显示类名).要用窗口的 进程标识符 (PID) 进行匹配, 请指定 ahk_pid %PID变量%.要使用 窗口组 进行匹配, 请指定 ahk_group GroupName.要使用窗口的 唯一 ID 进行匹配, 请指定 ahk_id %VarContainingID%.要减小检测范围, 请指定 多重条件.例如: My File.txt ahk_class Notepad
WinText 如果使用这个参数, 则它应该是目标窗口中某个文本元素的子字符串 (在 Window Spy 中会显示窗口中的文本元素).隐藏文本只有当 DetectHiddenText 设置为 ON 的时候才能检测到.
Interval 命令等待时对状态栏进行检查的时间间隔 (单位为毫秒), 可以是一个 表达式. 默认值是 50.
ExcludeTitle 标题中包含该参数指定的文字的窗口将被排除.
ExcludeText 文本元素中包含该参数指定的文字的窗口将被排除.

ErrorLevel

如果在目标状态栏出现匹配的字符串之前命令超时了, ErrorLevel 被设置为 1. 状态栏无法访问时, 它被设置为 2. 成功找到匹配, 它被设置为 0.

备注

StatusBarWait 尝试读取一个窗口中第一个 标准 状态栏 (类名为 msctls_statusbar32).? 某些程序使用它们自己的状态栏控件或者 MS 通用控件的特殊版本. 此命令不支持这样的状态栏.

通常情况下使用 StatusBarWait 命令比在一个循环中使用 StatusBarGetText 命令更有效率, 因为它包含了避免重复调用 StatusBarGetText 形成的高开销的优化.

StatusBarWait 在开始匹配的等待之前会确定它的目标窗口. 如果目标窗口关闭了, 即使存在另一个满足指定的 WinTitle 和 WinText 的窗口命令也将停止等待.

当该命令处于等待状态时, 新的 线程 可以通过 热键, 自定义菜单项, 或 计时器 启动.

窗口中的标题和文字是大小写敏感的.要检测隐藏窗口, 必须打开 DetectHiddenWindows.

相关

StatusBarGetText, WinGetTitle, WinGetText, ControlGetText

示例

; The following example enters a new search pattern into an existing Explorer/Search window.
IfWinExist, Search Results ; Sets the Last Found window to simplify the below.
{
    WinActivate
    Send, {tab 2}!o*.txt{enter}  ; In the Search window, enter the pattern to search for.
    Sleep, 400  ; Give the status bar time to change to "Searching".
    StatusBarWait, found, 30
    if ErrorLevel
        MsgBox, The command timed out or there was a problem.
    else
        MsgBox, The search successfully completed.
}

?

; The following example waits for the status bar of the active window to change. This example requires v1.0.46.06+.
SetTitleMatchMode RegEx
IfWinExist A  ; Set the last-found window to be the active window (for use below).
{
   StatusBarGetText, OrigText
   StatusBarWait, ^(?!^\Q%OrigText%\E$)  ; This regular expression waits for any change to the text.
}