一种取得Windows系统运行时间,且不同于GetTickCount的方法 Windows系统的应用程序编程接口函数(API)都是使用C/C++语言编写的,VB中使用系统API函数需要改写声明。 GetiTickCount函数的含义是:取得自Windows系统启动以来到现在所经过的时间(单位:ms)。 在VB6.0中,API函数: GetTickCount的声明如下:Private Declare Function GetTickCount Lib "kernel32" () As Long 在Windows中,该函数的原型是:DWORD GetiTickCount
Option ExplicitPrivate Declare Function osQueryPerformanceCounter Lib "kernel32" Alias "QueryPerformanceCounter" _ (lpPerformanceCount As Currency) As LongPrivate Declare Function osQueryPerformanceFrequency Lib "kernel32" Alias "QueryPerformanceFrequency" _ (lpFrequency As Currency) As LongPrivate Declare Function GetTickCount Lib "kernel32" () As Long'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'函数功能:计算Windows自启动以来所经历的时间(s)'返回类型:Double类型,你可以修改它,也可以返回整形。''%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Public Function Timer() As Double Dim freq As Currency Dim count As CurrencyOn Error GoTo errFun osQueryPerformanceFrequency freq '频率 相当于速度 v osQueryPerformanceCounter count '已发脉冲数 相当于距离 s Timer = count / freq '计算时间 t=s/v Exit FunctionerrFun: Timer = 0End FunctionPrivate Sub Form_Load() Text1.Text = "" Text2.Text = "" Timer1.Enabled = True Timer1.Interval = 1000End Sub'%%%%%%%%%%%%%%%%%%%%%%'过程功能:使用两个方法计算系统启动时间,实际测试,两者值有点误差。''%%%%%%%%%%%%%%%%%%%%%%%Private Sub Timer1_Timer() Text1.Text = Timer Text2.Text = GetTickCount * 0.001End Sub