1,486
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
Private Declare Function osQueryPerformanceCounter Lib "kernel32" Alias "QueryPerformanceCounter" _
(lpPerformanceCount As Currency) As Long
Private Declare Function osQueryPerformanceFrequency Lib "kernel32" Alias "QueryPerformanceFrequency" _
(lpFrequency As Currency) As Long
Private Declare Function GetTickCount Lib "kernel32" () As Long
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'函数功能:计算Windows自启动以来所经历的时间(s)
'返回类型:Double类型,你可以修改它,也可以返回整形。
'
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Public Function Timer() As Double
Dim freq As Currency
Dim count As Currency
On Error GoTo errFun
osQueryPerformanceFrequency freq '频率 相当于速度 v
osQueryPerformanceCounter count '已发脉冲数 相当于距离 s
Timer = count / freq '计算时间 t=s/v
Exit Function
errFun:
Timer = 0
End Function
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
Timer1.Enabled = True
Timer1.Interval = 1000
End Sub
'%%%%%%%%%%%%%%%%%%%%%%
'过程功能:使用两个方法计算系统启动时间,实际测试,两者值有点误差。
'
'%%%%%%%%%%%%%%%%%%%%%%%
Private Sub Timer1_Timer()
Text1.Text = Timer
Text2.Text = GetTickCount * 0.001
End Sub