|
请大侠们看下面程序,问题在注释中......
Global $t2, $t3 = 1
$Form1 = GUICreate("API定时器实例", 272, 139)
$Label1 = GUICtrlCreateLabel("00:00:00:00", 8, 8, 146, 17);时间
$Label2 = GUICtrlCreateLabel("0", 8, 56, 150, 17);+1
$Label3 = GUICtrlCreateLabel("", 8, 104, 148, 17);2的自乘
$Button1 = GUICtrlCreateButton("关闭定时器1", 168, 8, 89, 25, 0)
$Button2 = GUICtrlCreateButton("关闭定时器2", 168, 48, 89, 25, 0)
$Button3 = GUICtrlCreateButton("关闭定时器3", 168, 96, 89, 25, 0)
GUISetState(@SW_SHOW)
;hwnd;uint;uint;dword
$Timer = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword"); 问题1回调函数的参数是根据什么来设置的
$TimerDLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 1000, "ptr", DllCallbackGetPtr($Timer));1000毫秒执行一次
$Timer2DLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 200, "ptr", DllCallbackGetPtr($Timer));200毫秒执行一次
$Timer3DLL = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 2000, "ptr", DllCallbackGetPtr($Timer));2000毫秒执行一次
While 1
Switch GUIGetMsg()
Case - 3
ExitLoop
Case $Button1
DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL[0]);关闭定时器
Case $Button2
DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $Timer2DLL[0])
Case $Button3
DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $Timer3DLL[0])
EndSwitch
WEnd
GUIDelete()
DllCallbackFree($Timer);关闭回调
Func Timer($hWnd, $uiMsg, $idEvent, $dwTime)
;根据定时器ID来进行操作
Switch $idEvent; 问题2 这里$idEvent 这个参数如何获取定时器id的 不解不解
Case $TimerDLL[0]
GUICtrlSetData($Label1, @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC);更新时间
Case $Timer2DLL[0]
$t2 += 1
GUICtrlSetData($Label2, $t2);更新+1
Case $Timer3DLL[0]
$t3 *= 2
GUICtrlSetData($Label3, $t3);更新2的自乘
EndSwitch
EndFunc |
|