我对这类操作用得很少,似乎没遇到过
上面的没针对超时,要修改下
#include <Array.au3>
Local $hWin = _WinListWait('Uninstall Microsoft Office', '下一步(&N)', 10) ;10秒内检测等待
If Not @error Then MsgBox(0, '已检测到窗口', $hWin)
Func _WinListWait($sTitle, $sText = '', $iTimeout = 0)
Opt('WinTitleMatchMode', -1)
Local $hWin, $aTtList, $iTs = TimerInit()
If $iTimeout > 0 Then
$iTimeout *= 1000
Do
$hWin = WinGetHandle($sTitle, $sText)
If $hWin Then Return $hWin
$aTtList = WinList($sTitle, $sText)
If $aTtList[0][0] Then
MsgBox(0, '用 WinList 检测到窗口', $aTtList[1][1])
Return $aTtList[1][1]
EndIf
Sleep(100)
If TimerDiff($iTs) >= $iTimeout Then
Local $aList = WinList(), $aWShow[UBound($aList) + 1][3], $ix = 0
For $i = 1 To $aList[0][0]
If $aList[$i][0] <> '' And BitAND(WinGetState($aList[$i][1]), 2) Then
$ix += 1
$aWShow[$ix][0] = $aList[$i][0]
$aWShow[$ix][1] = $aList[$i][1]
$aWShow[$ix][2] = ($aList[$i][0] = $sTitle) ;测试是否与标题一致
EndIf
Next
If Not $ix Then Return SetError(2, 0, 0)
$aWShow[0][0] = $ix
ReDim $aWShow[$ix + 1][3]
_ArrayDisplay($aWShow, '已超时,未检测到窗口.当前可见窗口')
Return SetError(1, 0, 0)
EndIf
Until 0
EndIf
Do
$hWin = WinGetHandle($sTitle, $sText)
If $hWin Then Return $hWin
Sleep(100)
$aTtList = WinList($sTitle, $sText)
If $aTtList[0][0] Then
MsgBox(0, '用 WinList 检测到窗口', $aTtList[1][1])
Return $aTtList[1][1]
EndIf
Until 0
EndFunc ;==>_WinListWait
|