#pragma once #include "Mmsystem.h" extern void PASCAL OnTimer(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2); namespace Utility { class MyTimer { private: MMRESULT wTimerID; public: MyTimer(void) { } public: ~MyTimer(void) { timeKillEvent(wTimerID); timeEndPeriod(1); } public: bool CreateTimer() { TIMECAPS tc; UINT wTimerRes; if(timeGetDevCaps(&tc,sizeof(TIMECAPS))!=TIMERR_NOERROR) { ASSERT(0); return 0; } wTimerRes=min(max(tc.wPeriodMin,1),tc.wPeriodMax); timeBeginPeriod(wTimerRes); wTimerID=timeSetEvent(1,1,(LPTIMECALLBACK)OnTimer,NULL,TIME_PERIODIC); if(wTimerID==NULL) { ASSERT(0); } } }; }