Windows 下精確時間控制
I'm totally occupied recently.... :-( , i just can't spare out to type a word on the blog...
for measuring the time accuratly, I wrote double classes and share it...
copy too much code from CodeProject.com, so i contribute some...LOL
實在太忙……
最近要編寫一個即時波形繪圖程式,對時間要求比較高,研究了一下,寫出兩個類.共用源碼...
StopWatch
class MMTimer;
Description:
the class StopWatch for measuring the duration accuratly, 1ms differency.
the class MMTimer for triggering a callback function periodicly...
Example:
1)
StopWatch watch;
watch.Start();
//....your code to measure...
watch.Stop();
double duration = watch.Duration(); // in milliseconds
2)
MMTimer<CDialog1> timer;
timer.Start(10, this, &CDialog1::YourVoidProc);
...
代碼:
StopWatch StopWatch m_nFrequencyQueryPerformanceFrequencym_query m_nFrequency m_queryQuadPart Start Start QueryPerformanceCounterm_query m_nPrevCount m_queryQuadPart Stop QueryPerformanceCounterm_query m_nCurrCount m_queryQuadPart Durationm_nFrequencym_nCurrCount m_nPrevCount m_nFrequency __int64 m_nFrequency __int64 m_nPrevCount __int64 m_nCurrCount LARGE_INTEGER m_query T MMTimerTCallBackProcMMTimer m_nResolution m_nTimerIdNULL m_lpCallFromNULLTIMECAPS tctimeGetDevCapstcTIMECAPS TIMERR_NOERRORm_nResolution tcwPeriodMintimeBeginPeriodm_nResolution Start nDelay T lpCallFrom CallBackProc lpCallBackProcm_lpCallFrom lpCallFromm_callback lpCallBackProcm_nTimerId timeSetEventnDelay m_nResolution callbackDWORD_PTR TIME_PERIODIC m_nTimerId NULL Stopm_nTimerIdMMRESULT result timeKillEventm_nTimerIdresult TIMERR_NOERRORm_nTimerId result TIMERR_NOERRORMMTimerStopm_nResolutiontimeEndPeriodm_nResolution CALLBACK callbackUINT uTimerID UINT uMsg DWORD_PTR dwUser DWORD_PTR dw1 DWORD_PTR dw2MMTimerT lpTimerMMTimerTdwUserlpTimerm_lpCallFromlpTimerm_callbackCallBackProc m_callbackT m_lpCallFrom m_nResolution m_nTimerId