取得和設定計時器解析度

下列範例會呼叫 timeGetDevCaps 函式,以判斷計時器服務支援的最小和最大計時器解析度。 在設定任何計時器事件之前,此範例會使用 timeBeginPeriod 函式建立最小計時器解析度。

#define TARGET_RESOLUTION 1         // 1-millisecond target resolution

TIMECAPS tc;
UINT     wTimerRes;

if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) 
{
    // Error; application can't continue.
}

wTimerRes = min(max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax);
timeBeginPeriod(wTimerRes); 

使用多媒體計時器