推荐星级:
  • 1
  • 2
  • 3
  • 4
  • 5

VB6调用API函数编写的高精度定时器(含源码)

更新时间:2019-05-14 21:06:39 大小:30K 上传用户:zhangyonglin查看TA发布的资源 标签:api函数定时器 下载积分:8分 评价赚积分 (如何评价?) 打赏 收藏 评论(0) 举报

资料介绍

定时器精确到毫秒级。

Win10 64位、Win7 64位和32位测试通过。

下图所示,两秒钟定时精度为1.9946毫秒。

Windows系统的定时精度在16ms级。

如果你需要比10ms更精确的定时,这个测试软件能帮得上。

2019-05-14_21-08-50.jpg

2019-05-14_21-13-46.jpg

以下是模块的内容:


'获取CPU震荡基础频率:一个大整数

Public Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As LARGE_INTEGER) As Long

'获取时间计数器计数值

Public Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As LARGE_INTEGER) As Long

'大整数结构体

Public Type LARGE_INTEGER

    LowPart As Long

    HighPart As Long

End Type

'用于将大整数的字节复制到Currency类型,完成转换的工作

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length 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

'uDelay:        以毫秒指定事件的周期?

'Uresolution:   以毫秒指定延时的精度,数值越小定时器事件分辨率越高。缺省值为1ms。

'LpTimeProc:    指向一个回调函数?

'DwUser:        存放用户提供的回调数据?

'FuEvent:       指定定时器事件类型:

Public Const TIME_ONESHOT = &H0       ' uDelay毫秒后只产生一次事件

Public Const TIME_PERIODIC = &H1     ' 每隔uDelay毫秒周期性地产生事件

Public dwUser As Long

Public Tim_User As Long         '自定义定时器

Public Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long   '释放定时器事件


'********************获取系统时间****************************

Public Declare Function GetTickCount Lib "kernel32" () As Long '开机以来的毫秒数

Public Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)

Public Type SYSTEMTIME

        wYear As Integer

        wMonth As Integer

        wDayOfWeek As Integer

        wDay As Integer

        wHour As Integer    '世界UTC时间,和北京时间提前8小时

        wMinute As Integer

        wSecond As Integer

        wMilliseconds As Integer

End Type



'初始时间

Public initTime As LARGE_INTEGER

'每秒震动次数

Public freqCount As LARGE_INTEGER

'采样时振动器震动计数值

Public logTime As LARGE_INTEGER

'每秒震动次数的Currency类型数据

Public fFreq As Currency



Public CountX As Long

Public Count_All As Long '次数

Public mTime As Long  '定时器时常





Public Function Tim_FC1(ByVal uID As Long, ByVal uMsg As Long, ByVal dwUser As Long, ByVal dw1 As Long, ByVal dw2 As Long) As Long

     CountX = CountX + 1

End Function



'将一个长整型转换成高精度型数据

Public Function LargeIntToCurrency(liInput As LARGE_INTEGER) As Currency

    CopyMemory LargeIntToCurrency, liInput, LenB(liInput)

    LargeIntToCurrency = LargeIntToCurrency * 10000

End Function



    

部分文件列表

文件名大小
VB6定时器/
VB6定时器/Class1.cls2KB
VB6定时器/Form1.frm1KB
VB6定时器/Frm_Timer.frm6KB
VB6定时器/Module1.bas
VB6定时器/Mod_Timer.bas4KB
VB6定时器/MSSCCPRJ.SCC
VB6定时器/工程1.vbw
VB6定时器/工程Timer.exe
VB6定时器/工程Timer.pdb
VB6定时器/工程Timer.vbp1KB
...

全部评论(0)

暂无评论

上传资源 上传优质资源有赏金

  • 打赏
  • 30日榜单

推荐下载