Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > 综合其它

为access添加多个Timer功能

时 间:2008-03-19 12:18:13
作 者:andymark   ID:1350  城市:深圳
摘 要:为ACCESS添加多个Timer事件
正 文:

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

'模块代码:

'===============================================================
'功能: 添加多个计时器
'用法: 设置计时器 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

 



Access软件网QQ交流群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助