本帖最后由 yohoboy 于 2021-7-18 23:48 编辑
嘗試將板上的一個例子作改良 一个Msgbox倒计时的例子,
發現到怎麼弄無法針對MSGBOX的標誌設為1 時,隨時按下確定鈕或取消鈕或等計時到時
將Msbbox取回正確的返回值,總是返回上一次操作狀態的返回值。
例如第一次按下確定鈕,返回值是1,但是第二次按下取消鈕返回值還是1
第三次按下確定鈕返回值是2 ,怎麼調整代碼或是新增其他代碼判斷都無效。
所以上來請教大神怎麼改善這問題,謝謝抽空回覆。
附上代碼
#include "CoProc.au3" ;需另外加入擴充UDF
;_CoProc("Count_Down_0") ;測試過ok
_CoProc("Count_Down_1") ;有問題無法改善取回正確返回值
Func Count_Down_0()
$respond = MsgBox(0,"Count_Down_0", "_Count_Down_0")
While Not WinExists("Count_Down_0", "")
WEnd
$whd = WinGetHandle("Count_Down_0", "")
$n = 10
While $n > 0 And WinExists($whd)
$n = $n-1
ControlSetText($whd, "", "Button1", "確定["&$n&"]")
Sleep(1000)
WEnd
If WinExists($whd) Then ;用以非激活(啟用)狀態時,強制激活關閉視窗
WinActivate($whd)
ControlClick($whd, "", "Button1")
EndIf
MsgBox(0, "$respond", $respond)
EndFunc
Func Count_Down_1()
Global $whd= "", $respond = ""
$respond = MsgBox(1,"Count_Down_1", "_Count_Down_1")
While Not WinExists("Count_Down_1", "")
WEnd
$whd = WinGetHandle("Count_Down_1", "")
$n = 10
While $n > 0 And WinExists($whd)
$n = $n-1
ControlSetText($whd, "", "Button1", "確定["&$n&"]")
;ControlSetText($whd, "", "Button2", "取消["&$n&"]")
Sleep(1000)
WEnd
If WinExists($whd) Then ;用以非激活(啟用)狀態時,強制激活關閉視窗
WinActivate($whd)
ControlClick($whd, "", "Button1")
EndIf
If $respond = 1 Then
MsgBox(0, "確定", $respond)
ElseIf $respond = 2 Then
MsgBox(0,"取消",$respond)
EndIf
MsgBox(0,"主回應",$respond)
EndFunc
|