VB 中运用 TimeSetEvent 代替 Timer 控件
2009 年 05 月 24 日 星期日 10:43
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
参考
一、
使用 Winmm.dll 中导出的 API 函数: timeSetEvent 和 timeKillEvent。
1 timeSetEvent 的原形如下:
88 MMRESULT timeSetEvent(
88 UINT88888888888 uDelay,
88 UINT88888888888 uResolution,
88 LPTIMECALLBACK lpTimeProc,
88 DWORD_PTR888888 dwUser,
88 UINT88888888888 fuEvent
评论4