欢迎光临

木子屋

标题: VB6.0调用SetTimer实现定时器

作者: dnawo

日期: 2010-10-12 01:43 AM

分类: Win编程

内容: Timer.bas：
复制内容到剪贴板 程序代码Option Explicit
Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
MsgBox Now()
End Sub
窗体代码：
复制内容到剪贴板 程序代码Option Explicit
Dim lngTimerID As Long
Dim BlnTimer As Boolean
Private Sub Form_Load()
BlnTimer = False
Command1.Caption = "定时开始"
End Sub
Private Sub Form_Unload(Cancel As Integer)
KillTimer 0, lngTimerID
End Sub
Private Sub Command1_Click()
If BlnTimer = False Then
'每5秒钟调用一次函数
lngTimerID = SetTimer(0, 0, 5000, AddressOf TimerProc)
BlnTimer = True
Command1.Caption = "定时结束"
Else
KillTimer 0, lngTimerID
BlnTimer = False
Command1.Caption = "定时开始"
End If
End Sub
说明
TimerProc函数定义一定要放在bas模块文件中，否则运行代码"lngTimerID = SetTimer(0, 0, 5000, AddressOf TimerProc)"会报错，提示：操作符 AddressOf 使用无效。

+ 查看当前日志评论 (0)

登录

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 3.578 ms

返回

标题: VB6.0调用SetTimer实现定时器

你没有权限发表评论

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 3.578 ms

返回

暂无评论

返回

────────────

木子屋

PJBlog3 v3.2.9.518 Inside.

Processed In 3.674 ms

返回