Public lTimeID As Integer Public lTimeID2 As Integer
Public Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As LARGE_INTEGER) As Long Public Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As LARGE_INTEGER) As Long Public 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 Public Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long Public Declare Function GetTickCount Lib "kernel32" () As Long
2、创建定时器
private sub form1_click()
lTimeID2 = timeSetEvent(1000, 0, AddressOf TimeProcScan, 1, 1) If lTimeID2 = 0 Then MsgBox "cannot excute timesetevent2" End If lTimeID = timeSetEvent(100, 0, AddressOf TimeProcAcq, 1, 1) If lTimeID = 0 Then MsgBox "cannot excute timesetevent" End If
end sub
3、定义回调函数(在MOUDLE.ABS中定义)
Public Function TimeProcAcq(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long) end Function
Public Function TimeProcScan(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long) end Function
4、删除进程(一定要在程序退出之前删除)
Private Sub Form_Unload(Cancel As Integer) If lTimeID Then timeKillEvent (lTimeID) End If If lTimeID2 Then timeKillEvent (lTimeID2) End If End End Sub