找回密码
 加入
搜索
查看: 3122|回复: 2

[系统综合] 阅读API定时器的一些问题

[复制链接]
发表于 2013-6-14 18:13:45 | 显示全部楼层 |阅读模式
请大侠们看下面程序,问题在注释中......

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
发表于 2013-6-15 06:55:31 | 显示全部楼层
问题1:根据Timer函数来的------------Timer($hWnd, $uiMsg, $idEvent, $dwTime)

问题2:因为每个id的名称不同--------------$TimerDLL , $Timer2DLL ,$Timer3DLL
 楼主| 发表于 2013-6-15 18:29:48 | 显示全部楼层
嗯,有点理解了,谢谢!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-1 07:06 , Processed in 0.083189 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表