Obtaining and Setting Timer Resolution

[The feature associated with this page, Multimedia Timers, is a legacy feature. It has been superseded by Multimedia Class Scheduler Service. Multimedia Class Scheduler Service has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Multimedia Class Scheduler Service instead of Multimedia Timers, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

The following example calls the timeGetDevCaps function to determine the minimum and maximum timer resolutions supported by the timer services. Before it sets up any timer events, the example establishes the minimum timer resolution by using the timeBeginPeriod function.

#define TARGET_RESOLUTION 1         // 1-millisecond target resolution

UINT     wTimerRes;

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

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

Using Multimedia Timers