越多的容错机制越能让程序兼容性更强。因此,能遇到这些问题不是坏事。
下次直接测试本楼的,增加了调试信息#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, $iTs = TimerInit()
If $iTimeout > 0 Then
$iTimeout *= 1000
Do
$hWin = WinGetHandle($sTitle, $sText)
If $hWin Then Return $hWin
$hWin = __WinListCk($sTitle, $sText)
If $hWin Then
MsgBox(0, '__WinListCk 已检测到窗口', $hWin)
Return $hWin
EndIf
Sleep(100)
If TimerDiff($iTs) >= $iTimeout Then
Local $aList = WinList(), $aWShow[UBound($aList) + 1][5], $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)
If $aWShow[$ix][2] And $sText <> '' Then
$aWShow[$ix][3] = WinGetText($aList[$i][1])
$aWShow[$ix][4] = StringInStr($aWShow[$ix][3], $sText)
EndIf
EndIf
Next
If Not $ix Then Return SetError(2, 0, 0)
$aWShow[0][0] = $ix
ReDim $aWShow[$ix + 1][5]
_ArrayDisplay($aWShow, '已超时,未检测到窗口.当前可见窗口')
Return SetError(1, 0, 0)
EndIf
Until 0
EndIf
Do
$hWin = WinGetHandle($sTitle, $sText)
If $hWin Then Return $hWin
$hWin = __WinListCk($sTitle, $sText)
If $hWin Then
MsgBox(0, '__WinListCk 已检测到窗口', $hWin)
Return $hWin
EndIf
Sleep(100)
Until 0
EndFunc ;==>_WinListWait
Func __WinListCk($sTitle, $sText)
Local $aList = WinList()
For $i = 1 To $aList[0][0]
If $aList[$i][0] <> '' And BitAND(WinGetState($aList[$i][1]), 2) Then
If StringRegExp($aList[$i][0], '(?i)^\Q' & $sTitle & '\E') Then
If $sText = '' Then Return $aList[$i][1]
If StringInStr(WinGetText($aList[$i][1]), $sText) Then Return $aList[$i][1]
EndIf
EndIf
Next
Return SetError(1, 0, 0)
EndFunc ;==>__WinListCk
|