用API:timeSetEvent做高精度定时器
「已注销」 2002-05-09 03:06:57 我的代码如下,但出现非法错误,不知何故?
在form1中加两个command和一个text,下面是FORM中的代码
Private Declare Function timeBeginPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
Private Declare Function timeEndPeriod Lib "winmm.dll" (ByVal uPeriod As Long) As Long
Private Sub Command1_Click()
If timeBeginPeriod(40) = 0 Then
lngReturn = timeSetEvent(50, 2, AddressOf timeSetEventProc, 1, 1)
End If
End Sub
Private Sub Command2_Click()
timeEndPeriod (40)
Module1.Stopt
End Sub
下面是在MODULE1中的代码
Option Explicit
Public Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long,ByVal uResolution As Long, ByVal lpFunction As Any, ByVal dwUser As Long, ByVal uFlags As Long) As Long
Public Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long
Public js As Long
Public Function timeSetEventProc() As Long
Static js As Long
js = js + 1
Form1.Text1 = js
End Function
Public Sub Stopt()
timeKillEvent lngReturn
End Sub
给分条件:请给个可行的例子。