VB6.0调用SetTimer实现定时器

VB6.0调用SetTimer实现定时器
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 使用无效。
分类: 代码
1
0
« 上一篇: cmd命令控制台窗口一闪就消失解决办法
» 下一篇: 外网SQL服务器设置
posted @ 2011-05-27 19:29 MyFavorite 阅读( 4633) 评论( 1) 编辑 收藏

  
#1楼 2593273 2013/1/5 23:41:17 2013-01-05 23:41 | 宏 信  
講解的很好


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值