会员登录 - 用户注册 - 网站地图 Office中国(office-cn.net),专业Office论坛
当前位置:主页 > 技巧 > Access技巧 > 模块函数VBA > 正文

为ACCESS添加多个Timer功能

时间:2009-06-13 08:54 来源:本站原创 作者:andymark 阅读:

 

 

 

众所周知,access只有一个Timer事件,并不能处理多个触发事件,感觉十分不爽。
     现在我们可以借助API轻松实现多个定时器,而且调用也比较方便,下面是个简单的例子

QUOTE:

'模块代码:

'===============================================================
'功能: 添加多个计时器
'用法: 设置计时器 SetTimer Me.hwnd, 1, 10000, AddressOf TimerProc1
' 关闭计时器 KillTimer Me.hwnd, 1
'作者: andymark
' QQ : 42503577 ewang11@163.com
'
'=================================================================


Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
'创建一个计时器
'参数: hwnd 窗口句柄
' nIDEvent 定时器ID,多个定时器时,可以通过该ID判断是哪个定时器
' uElapse 时间间隔,单位为毫秒
' lpTimerFunc 回调函数

Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
'关闭销毁计时器


'Timer回调涵数
Public Sub TimerProc1(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
MsgBox "测试第1个Timer事件"
End Sub
Public Sub TimerProc2(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
MsgBox "测试第2个Timer事件"
End Sub

Public Sub TimerProc3(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
MsgBox "测试第3个Timer事件"
End Sub


'窗体代码

Private Sub Form_Load()
'设置10秒间隔,调用回调涵数TimerProc1
SetTimer Me.hwnd, 1, 10000, AddressOf TimerProc1
'设置4秒间隔,调用回调涵数TimerProc2
SetTimer Me.hwnd, 2, 4000, AddressOf TimerProc2
'设置14秒间隔,调用回调涵数TimerProc3
SetTimer Me.hwnd, 3, 14000, AddressOf TimerProc3
End Sub

Private Sub Form_Unload(Cancel As Integer)
'关闭所有计时器
KillTimer Me.hwnd, 1
KillTimer Me.hwnd, 2
KillTimer Me.hwnd, 3
End Sub

(责任编辑:admin)

顶一下
(0)
0%
踩一下
(0)
0%
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价: