为access添加多个Timer功能-andymark
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> 综合其它


为access添加多个Timer功能

发表时间:2008/3/19 12:18:13 评论(2) 浏览(7085)  评论 | 加入收藏 | 复制
   
摘 要:为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群(群号:198465573)
 
 相关文章
为access添加多个Timer功能  【andymark  2008/3/19】
常见问答
技术分类
相关资源
文章搜索
关于作者

andymark

文章分类

文章存档

友情链接