今天項目中60秒倒計時模塊需要用到GetTickCount(),這個函數,在此做下整理和總結。
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.
返回值:如正確,返回毫秒數。
2.用法及應用
(1)用來計算系統所用時間,即計算兩個時間點的時間間隔
DWORD dwStart = ::GetTickCount();
//執行操作
.......
DWORD dwStop = ::GetTickCount();
DWORD dwInterval = dwStop - dwStart;
(2)用於定時
用於定時器效果,比如用於60秒倒計時:
static int n_gTimeout = 0
n_gTimeout = ::GetTickCount()/1000;
//....執行操作
int nInterval = ::GetTickCount()/1000 - n_gTimeout;
if(nInterval >=60)
{
return;
}
m_nTimeOut = 60 - nInterval;//倒計時時刻