设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

为ACCESS添加多个Timer功能

2008-3-18 23:13| 发布者: andymark| 查看: 2272| 评论: 15

众所周知,ACCESS只有一个Timer事件,并不能处理多个触发事件,感觉十分不爽。 现在我们可以借助API轻松实现多个定时器,而且调用也比较方便,下面是个简单的例子 [quote] '模块代码: '=============================================================== '功能: 添加多个计时器 '用法: 设置计时器 SetTimer Me.hwnd, 1, 10000, AddressOf TimerProc1 ' 关闭计时器 KillTimer Me.hwnd, 1 '作者: andymark ' QQ : 42503577 [email=ewang11@163.com]ewang11@163.com[/email] ' '================================================================= 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 [/quote] [hide][attach]28983[/attach][/hide]详细内容:http://www.office-cn.net/forum.php?mod=viewthread&tid=60481
发表评论

最新评论

查看全部评论(15)

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-4-25 21:19 , Processed in 0.085273 second(s), 16 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部