adlibregister在跳出msg窗口时会停止,建议用timer
#include <winapiex.au3>
Global $itimer1=1, $itimer2 = 2
Global $time1= 60, $time2 = 60
Global $hTimerProc1 = DllCallbackRegister('_TimerProc1', 'none', 'hwnd;uint;uint_ptr;dword')
Global $hTimerProc2 = DllCallbackRegister('_TimerProc2', 'none', 'hwnd;uint;uint_ptr;dword')
AutoItSetOption("GUIOnEventMode", 1)
GUICreate("倒计时例子", 420, 140)
GUISetOnEvent(-3, "quit")
GUICtrlCreateGroup("倒计时一",10,10, 180, 120)
$htLabel1 = GUICtrlCreateLabel("00:60",20,40)
GUICtrlCreateButton("开始计时",20, 80)
GUICtrlSetOnEvent(-1, "time1")
GUICtrlCreateButton("停止计时",120, 80)
GUICtrlSetOnEvent(-1, "stop1")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("倒计时二",230,10, 180, 120)
$htLabel2 = GUICtrlCreateLabel("00:60",240,40)
GUICtrlCreateButton("开始计时",240, 80)
GUICtrlSetOnEvent(-1, "time2")
GUICtrlCreateButton("停止计时",340, 80)
GUICtrlSetOnEvent(-1, "stop2")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState()
While 1
Sleep(10)
WEnd
Func quit()
stop1()
stop2()
DllCallbackFree($hTimerProc1)
DllCallbackFree($hTimerProc2)
Exit
EndFunc
Func time1()
$itimer1 = _WinAPI_SetTimer (0, $itimer1, 1000, DllCallBackGetPtr($hTimerProc1) )
EndFunc
Func time2()
$itimer2 = _WinAPI_SetTimer (0, $itimer2, 1000, DllCallBackGetPtr($hTimerProc2) )
EndFunc
Func stop1()
_WinAPI_KillTimer(0, $itimer1)
EndFunc
Func stop2()
_WinAPI_KillTimer(0, $itimer2)
EndFunc
Func _TimerProc1($hWnd, $iMsg, $iTimerId, $iTime)
$time1 -= 1
If $time1 = 0 Then
_WinAPI_KillTimer(0, $itimer1)
GUICtrlSetData($htLabel1, secondfunc($time1))
MsgBox(0,"","计时一停止!")
Else
GUICtrlSetData($htLabel1, secondfunc($time1))
EndIf
EndFunc
Func _TimerProc2($hWnd, $iMsg, $iTimerId, $iTime)
$time2 -= 1
If $time2 = 0 Then
_WinAPI_KillTimer(0, $itimer2)
GUICtrlSetData($htLabel2, secondfunc($time2))
MsgBox(0,"","计时二停止!")
Else
GUICtrlSetData($htLabel2, secondfunc($time2))
EndIf
EndFunc
Func secondfunc($second)
Return(StringFormat("%02d:%02d", Int($second/60), Mod($second, 60)))
EndFunc
|