那片叶子 发表于 2014-3-24 10:38:33

几个倒计时互不干扰怎么写?



如图:有几个倒计时,我设置好时间后,点击倒计时一中开始倒计时,诺干分钟后,我在设置倒计时二中时间进行倒计时,哪个倒计时完就弹出框框,几个倒计时互不干扰,怎么写啊!求救!

35888894 发表于 2014-3-24 11:38:43

弄两个变量
AdlibRegister

seniors 发表于 2014-3-24 12:26:41

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

那片叶子 发表于 2014-3-24 13:18:45

{:face (427):}谢谢!
页: [1]
查看完整版本: 几个倒计时互不干扰怎么写?