SetTimer这个东西不准,谁还有好的方法?

解决方案 »

  1.   

    如果只需毫米级精度,好好看看MSDN上对这几个函数的介绍,可以用timeSetEvent  实现自己的定时器 
      
    timeBeginPeriod  
    timeEndPeriod  
    timeGetDevCaps  
    timeGetSystemTime  
    timeGetTime  
    timeKillEvent  
    TimeProc  
    timeSetEvent  
      

  2.   

    QueryPerformanceFrequency()和QueryPerformanceCounter()要准确多了
      

  3.   


    void CMPFMSDoc::StartHighTimer()
    {

    TIMECAPS timecaps;
    int TimerResolution;
    //i=0;
    //从系统获得关于定时器服务能力的信息,
    //分辨率不能超出系统许可值(1到16毫秒)
    if (timeGetDevCaps(&timecaps,sizeof(TIMECAPS))==TIMERR_NOERROR)
    TimerAccuracy=Min(Max(timecaps.wPeriodMin,
    Accuracy),timecaps.wPeriodMax);

    timeBeginPeriod(TimerAccuracy);
    //设置定时器分辨率

    TimerResolution=m_sample_delta; //设置定时间隔为5毫秒

    //产生间隔5毫秒,周期执行的定时器事件;启动定时器

    //PointFunction=HighTimerCallProc;//把HighTimerCallProc函数的地址赋予函数指针*PointFunction

    TimerID = timeSetEvent(TimerResolution,TimerAccuracy,(LPTIMECALLBACK)HighTimerCallProc,(DWORD)this,TIME_PERIODIC);
    if(TimerID==0)

    // // AfxMessageBox ("不能进行定时!"); 
    AfxMessageBox("不能进行定时!");

    }void CALLBACK CMPFMSDoc::HighTimerCallProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1,DWORD dw2)
    //void CALLBACK HighTimerCallProc()
    {
    ..................你要做的事情
    }以上是多媒体精密定时器