VB中运用TimeSetEvent代替Timer控件

窗体代码:
程序代码 程序代码

Option Explicit
Private Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long
Private Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long, ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As Long, ByVal uFlags As Long) As Long
Dim p As Long
Private Const TIME_周期 As Long = 1
Private Const TIME_一次性 As Long = 0

Private Sub Form_DblClick()
    timeKillEvent p
    p = 0
End Sub

Private Sub Form_Load()
    p = timeSetEvent(300000, 10, AddressOf TimeProc, 1, TIME_一次性)
    Debug.Print timeGetTime
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    If p Then timeKillEvent p: p = 0: Cancel = True: Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
    Timer1.Enabled = False
    Unload Me
End Sub


模块代码:
程序代码 程序代码

Option Explicit
Public Declare Function timeGetTime Lib "winmm.dll" () As Long

Sub TimeProc(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long)
    Debug.Print timeGetTime
End Sub


TimeProc过程中debug.print语句可以换成你想要的……


文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.