转自:http://www.cnblogs.com/jxsoft/archive/2011/10/17/2215366.html
DWORD GetTickCount(void);
1) 定义
For Release configurations, this function returns the number of milliseconds since the device booted, excluding any time that the system was suspended. GetTickCount starts at 0 on boot and then counts up from there.
在Release版本中,该函数从0开始计时,返回自设备启动后的毫秒数(不含系统暂停时间)。
For Debug configurations, 180 seconds is subtracted from the the number of milliseconds since the device booted. This allows code that uses GetTickCount to be easily tested for correct overflow handling.
在Debug版本中,设备启动后便从计时器中减去180秒。这样方便测试使用该函数的代码的正确溢出处理。
Return Values
The number of milliseconds indicates success.
返回值:如正确,返回毫秒数。
Header: Winbase.h.
Link Library: Coredll.lib.
2) 应用
用来计算某个操作所使用的时间:
...//执行耗时的操作
Stop:=GetTickCount;
TimeUsed:=(Stop-Start)/1000; //使用了xxx秒
用来定时:
void main()
{
DWORD dwLast;
DWORD dwCurrent;
DWORD dwInterval = 1000;
dwLast = GetTickCount();
int i = 0;
while(true)
{
dwCurrent = GetTickCount();
if( dwCurrent - dwLast < dwInterval )
continue;
//your code to be executed when interval is elapsed
printf("dwLast,dwCurrent,diff:%d,%d,%d ",dwLast,dwCurrent,dwCurrent-dwLast);
//your code to determine when to break
if( i > 10 ) break;
i++;
dwLast = dwCurrent;
printf("Time is up!");
break;
}
getchar();
return;
}
对于一般的实时控制,使用GetTickCount()函数就可以满足精度要求,但要进一步提高计时精度,就要采用QueryPerformanceFrequency()函数和QueryPerformanceCounter()函数。这两个函数是VC提供的仅供Windows 9X使用的高精度时间函数,并要求计算机从硬件上支持高精度计时器。
以上引用:
http://www.wesoho.com/article.asp?id=2072
http://bitboy.blog.edu.cn/user1/19986/archives/2005/1001846.shtml
相关推荐
工程用VB6编写,其他语言用法也一样。 1000.0006 误差 00.00 CPU计时QueryPerformanceCounter 0999.3995 误差 00.60 timeGetTime 0989.1456 误差 10.85 gettickcount优化 0999.3569 误差 00.64 gettickcount
1、在Linux实现Win32 API之GetTickCount函数 为了将Windows中的GetTickCount API函数移植到Linux,可以使用如下的代码: long GetTickCount() { tms tm; return times(&tm); } 2、Windows和...
总结了常用的四种方法。包括: 方法一 利用 SYSTEMTIME 方法二 利用 GetTickCount()函数 方法三 使用clock()函数 方法四 获取高精度时间差 个人感觉还是很清晰明了的。希望对大家有用。
方法一 利用 SYSTEMTIME 方法二 利用 GetTickCount()函数 方法三 使用clock()函数 方法四 获取高精度时间差
在表单的 Load 和 Destroy 事件中增加对 API 函数 GetTickCount 的声明和释放 (2)重要更新:编写直接从 VFP 表中读取 Vouch 表数据到 itGrid 控件中的代码 a. 新增 表单的 LoadDataFromDbf 方法代码 b. 新增 表单...
VB闹钟,基于GetTickCount API函数的定时器闹钟,程序简单,可学习下GetTickCount的用法,程序运行界面如演示截图所示。
总结了常用的四种方法。包括: 方法一 利用 SYSTEMTIME 方法二 利用 GetTickCount()函数 方法三 使用clock()函数 方法四 获取高精度时间差 个人感觉还是很清晰明了的。希望对大家有用。
这里再重申一遍,如果不到万不得以,不要随便使用Variant 类型,还是应坚持使用传统的Pascal 数据类型和类型检查方法。在Delphi 和 VCL中,variant变量主要是用于 OLE 支持和数据库域的访问。 Variant类型内部结构...
1. 使用clock() 函数;2. 使用time() 函数;3. 使用GetTickCount () 函数;4. 使用QueryFrequencyCount () 函数。
但是,在Windows 2000中提供了一个新的函数:GetLastInputInfo(),这个函数使用结构 LASTINPUTINFO 作为参数: LASTINPUTINFO lpi; lpi.cbSize = sizeof(lpi); GetLastInputInfo(&lpi); 调用函数...
根据上面的流程图可以看到如果是一步一步的写程序,势必会让程序变得冗长且不易阅读,因而我想到使用循环的方法,将流程图中类似的结构体做成一个循环体来实现,使程序源代码变得十分的简洁,且容易被阅读和修改。...