免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5524 | 回复: 0
打印 上一主题 下一主题

timeGetTime API函数 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-28 15:18 |只看该作者 |倒序浏览
想在程序中加一个计时的功能,记录从开始游戏时经过的时间,以秒为单位。翻了下资料,发现timeGetTime这个api函数正和我意。先粘来函数在MSDN上的介绍。

timeGetTime
The timeGetTime function retrieves the system time, in milliseconds. The system time is the time elapsed since Windows was started.

DWORD timeGetTime(VOID); Parameters
This function does not take parameters.

Return Values
Returns the system time, in milliseconds.

Remarks
The only difference between this function and the timeGetSystemTime function is that timeGetSystemTime uses the MMTIME structure to return the system time. The timeGetTime function has less overhead than timeGetSystemTime.

Note that the value returned by the timeGetTime function is a DWORD value. The return value wraps around to 0 every 2^32 milliseconds, which is about 49.71 days.This can cause problems in code that directly uses the timeGetTime return value in computations, particularly where the value is used to control code execution. You should always use the difference between two timeGetTime return values in computations.

Windows NT: The default precision of the timeGetTime function can be five milliseconds or more, depending on the machine. You can use the timeBeginPeriod and timeEndPeriod functions to increase the precision of timeGetTime. If you do so, the minimum difference between successive values returned by timeGetTime can be as large as the minimum period value set using timeBeginPeriod and timeEndPeriod. Use the QueryPerformanceCounter and QueryPerformanceFrequency functions to measure short time intervals at a high resolution,

Windows 95: The default precision of the timeGetTime function is 1 millisecond. In other words, the timeGetTime function can return successive values that differ by just 1 millisecond. This is true no matter what calls have been made to the timeBeginPeriod and timeEndPeriod functions.

       不是很难,但看完也够麻烦的了。大致意思就是说,timeGetTime这个函数,记录的是从windows开机到现在经历的时间,单位为毫秒。函数返回值为DWORD,即双字,所以范围为0-2^32。这个函数没有参数。声明的话,在VB中可以用API浏览器直接复制就ok了。

      Private Declare Function timeGetTime Lib "winmm.dll" () As Long

    使用很简单,只是要注意的是,不要直接用它的返回值参加计算。这样很容易出问题,最好使用两次函数调用返回值的差值参与计算。在WIN NT中,他默认的精度是5毫秒。如果你要使精度更高些,就要用timeBeginPeriod 和timeEndPeriod函数。如果要求在更高要求的环境下测度时间间隔就要用QueryPerformanceCounter 和QueryPerformanceFrequency两个函数了。具体用法参考相关资料。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP