tts780679 发表于 2013-6-14 18:13:45

阅读API定时器的一些问题

请大侠们看下面程序,问题在注释中......

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);关闭定时器
                Case $Button2
                        DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $Timer2DLL)
                Case $Button3
                        DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $Timer3DLL)
        EndSwitch
WEnd
GUIDelete()
DllCallbackFree($Timer);关闭回调

Func Timer($hWnd, $uiMsg, $idEvent, $dwTime)
;根据定时器ID来进行操作
Switch $idEvent;问题2 这里$idEvent 这个参数如何获取定时器id的 不解不解
        Case $TimerDLL
                GUICtrlSetData($Label1, @HOUR & ":" & @MIN & ":" & @SEC & ":" & @MSEC);更新时间
        Case $Timer2DLL
                $t2 += 1
                GUICtrlSetData($Label2, $t2);更新+1
        Case $Timer3DLL
                $t3 *= 2
                GUICtrlSetData($Label3, $t3);更新2的自乘
EndSwitch
EndFunc

haijie1223 发表于 2013-6-15 06:55:31

问题1:根据Timer函数来的------------Timer($hWnd, $uiMsg, $idEvent, $dwTime)

问题2:因为每个id的名称不同--------------$TimerDLL , $Timer2DLL ,$Timer3DLL

tts780679 发表于 2013-6-15 18:29:48

嗯,有点理解了,谢谢!
页: [1]
查看完整版本: 阅读API定时器的一些问题