本帖最后由 南一 于 2012-8-18 20:55 编辑
使用API定时器来控制
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $s = 5
$Form1 = GUICreate("Form1", 297, 122, 192, 124)
$Button1 = GUICtrlCreateButton("倒计时(" & $s & "秒)", 80, 72, 129, 33)
GUISetState(@SW_SHOW)
$Timer = DllCallbackRegister("_daojishi", "int", "hwnd;uint;uint;dword")
$TimerDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 1000, "ptr", DllCallbackGetPtr($Timer))
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $Button1
DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL[0])
Exit
EndSwitch
WEnd
Func _daojishi($hWnd, $uiMsg, $Form1_idEvent, $dwTime)
If $s < 1 Then
GUICtrlSetData($Button1, "退出")
Exit
EndIf
$s -= 1
GUICtrlSetData($Button1, "倒计时(" & $s & "秒)")
EndFunc ;==>_daojishi
|