VB中运用TimeSetEvent代替Timer控件
作者:JiaJia 日期:2007-07-12
窗体代码:
程序代码
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语句可以换成你想要的……
程序代码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语句可以换成你想要的……
评论: 0 | 引用: 0 | 查看次数: -
发表评论
上一篇
下一篇

文章来自:
Tags: