win 32api之:GetTickCount
来源:互联网 发布:广州专利代理待遇知乎 编辑:程序博客网 时间:2024/05/20 20:48
GetTickCount函数 函数功能:GetTickCount返回(retrieve)从操作系统启动到现在所经过(elapsed)的毫秒数,它的返回值是DWORD。
函数原型:
DWORD GetTickCount(void);
VB版
VB声明:
Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
例如:实现延时
Public Sub Sleep(numa As Long)
Dim num1 As Long
Dim num2 As Long
Dim numb As Long
numb = 0
num1 = GetTickCount
Do While numa - numb > 0
num2 = GetTickCount
numb = num2 - num1
DoEvents
Loop
End Sub
C++版
CString s;
DWORD k=::GetTickCount(); //获取毫秒级数目
int hm=k/3600000; //hm为小时数
int ms=(k-3600000*hm)/60000; //ms为分钟数
int se=(k-3600000*hm-60000*ms)/1000; //se为秒数(除以1000是因为k精确到毫秒)
s.Format("%d:%d:%d",hm,ms,se); //输出时、分、秒
库文件:kernl32.dll
C/C++头文件:winbase.h
windows程序设计中可以使用头文件windows.h
程序示例
//代替time函数来初始化随机数生成器
#include<stdio.h>
#include<windows.h>
int main()
{
int i,k,r;
for(i=0;i<10;i++)
{
srand(GetTickCount());
printf("/n");
for(k=0;k<5;k++)
{
r=rand();
printf("%d ",r);
}
}
return 0;
}
注意事项
GetTickcount函数:它返回从操作系统启动到当前所经过的毫秒数,常常用来判断某个方法执行的时间,其函数原型是DWORD GetTickCount(void),返回值以32位的双字类型DWORD存储,因此可以存储的最大值是2-1 ms约为49.71天,因此若系统运行时间超过49.71天时,这个数就会归0,MSDN中也明确的提到了:"Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days."。因此,如果是编写服务器端程序,此处一定要万分注意,避免引起意外的状况。
- win 32api之:GetTickCount
- Windows API GetTickCount函数
- WIN 32 串口API
- WIN-32 API
- Win API HOOK 之 Detours
- 未分类--Windows API--GetTickCount
- GetTickCount
- GetTickCount
- GetTickCount
- Win API通用对话框之GetOpenFileName
- win api
- win 32Api获取系统内存函数
- win API之航空客运订票系统(课程设计)
- Windows API一日一练(69)GetTickCount函数
- Windows API一日一练(69)GetTickCount函数
- Windows API一日一练(69)GetTickCount函数
- Windows API一日一练(69)GetTickCount函数
- Windows API一日一练(69)GetTickCount函数
- SQLServer和Oracle的常用函数对比
- BIEE : ibot 配置(Schedule 服务)
- MVC2.0 基础知识
- NFL Playoffs 2011: How to Find the Perfect NFL Cheerleader
- 关于Android权限的一些文章
- win 32api之:GetTickCount
- Python多行注释
- 获取CPU制造商----读注册表
- UNetbootin 制作U盘启动盘
- 切换jdk版本
- RBAC权限体系设计UML
- DES加密与解密算法
- 使用__FILE__得到当前源文件的文件名&使用__LINE__得到当前所在行数
- NBA: Kobe Bryant, Michael Jordan and the Greatest Pick-Up Game Ever