zoukankan      html  css  js  c++  java
  • 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 使用无效。
  • 相关阅读:
    JS 字符串
    JS 变量
    JS 数据类型与运算符
    HTML加载动画实现
    DOM Document.readyState 属性
    html中怎么去掉input获取焦点时候的边框
    原生js获取子元素
    CSS3 Animation动画
    slice,substr和substring的区别
    a链接嵌套无效,嵌套链接最优解决办法
  • 原文地址:https://www.cnblogs.com/MyFavorite/p/2060208.html
Copyright © 2011-2022 走看看