shamantou blog site

shamantou@gmail.com

导航

Hight resolution timer

#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);
            }
        }
 
    };
}

 

[download here] MyTimer.h

<< STL中Set介绍【转】PostgreSQL Example >>

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最近发表

Powered By Z-Blog 1.8 Arwen Build 81206 Copyright 2006-2009 | ooplab.org | shamantou@gmail.com | 沪ICP备08011244号 | Some Rights Reserved.