📄 cintervaltimer.cpp
字号:
// ARM Ltd
// Copyright 1998 All Rights reserved
// David Earlam 22.9.1998
// helper class to call a function every n milliseconds
// WM_TIMER (CWnd->SetTimer() is useless below 55mSecs which equates to a periodic rate
// of only 19.2 Hertz.
//
//
#include <afxwin.h>
#include "CintervalTimer.h"
#define TARGET_RESOLUTION 1 /* Try for 1-millisecond accuracy. */
CIntervalTimer::CIntervalTimer()
{
m_wTimerRes=0;
m_wTimerID=0;
}
CIntervalTimer::~CIntervalTimer()
{
StopPeriodicTimer();
FreeTimerResolution();
}
UINT CIntervalTimer::SetTimerCallback(DWORD dwUser,
UINT msInterval, /* Event interval */
LPTIMECALLBACK lpMMTimeProc )
{
TIMECAPS tc;
#if 0
DWORD dwVersion;
dwVersion = GetVersion();
if (LOBYTE(LOWORD(dwVersion))<4) /*win32s*/
{
m_wTimerID=SetTimer(NULL,0,msInterval,(TIMERPROC)BumpProgressWin32sTimerProc);
}
else
#endif
{
if(timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR)
{
return TIMERR_NOCANDO;
}
m_wTimerRes = min(max(tc.wPeriodMin, TARGET_RESOLUTION),
tc.wPeriodMax);
timeBeginPeriod(m_wTimerRes);
m_wTimerID = timeSetEvent(
msInterval, /* Delay */
m_wTimerRes, /* Resolution */
(LPTIMECALLBACK) lpMMTimeProc, /* Callback function */
(DWORD) dwUser, /* User data */
TIME_PERIODIC); /* Event type (periodic) */
}
if (m_wTimerID == 0)
return TIMERR_NOCANDO;
else
return TIMERR_NOERROR;
}
void CIntervalTimer::FreeTimerResolution(void)
{
if (m_wTimerRes != 0)
timeEndPeriod(m_wTimerRes);
}
void CIntervalTimer::StopPeriodicTimer(void)
{
if (m_wTimerID != 0)
{ /* If timer event is pending */
DWORD dwVersion;
dwVersion = GetVersion();
if (LOBYTE(LOWORD(dwVersion))<4) /*win32s*/
{
KillTimer(NULL,m_wTimerID);
}
else
{
timeKillEvent(m_wTimerID); /* Cancel the event */
}
m_wTimerID = 0;
}
}
#if 0
/*no multimedia timers in win32s, use a lowly WM_TIMER callback to simulate*/
void CALLBACK BumpProgressWin32sTimerProc( HWND hwnd,/* handle of window for timer messages*/
UINT uMsg, /* WM_TIMER message*/
UINT idEvent, /* timer identifier*/
DWORD dwTime )/*Universal Coordinated Time*/
{
BumpProgressMMTimeProc(idEvent,WM_TIMER,(DWORD) &myProgressData,dwTime,0);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -