mmtimers.cpp
来自「采集电压 用研华6220板卡采集电压值 实时显示 电压变化」· C++ 代码 · 共 65 行
CPP
65 行
#include "StdAfx.h"
#include "mmTimers.h"
CMMTimers::CMMTimers(UINT resolution) : timerRes(0), timerId(0)
{
TIMECAPS tc;
if (TIMERR_NOERROR == timeGetDevCaps(&tc,sizeof(TIMECAPS)))
{
timerRes = min(max(tc.wPeriodMin,resolution),tc.wPeriodMax);
timeBeginPeriod(timerRes);
}
}
CMMTimers::~CMMTimers()
{
stopTimer();
if (0 != timerRes)
{
timeEndPeriod(timerRes);
timerRes = 0;
}
}
extern "C"
void
CALLBACK
internalTimerProc(UINT id,UINT msg,DWORD dwUser,DWORD dw1,DWORD dw2)
{
CMMTimers * timer = (CMMTimers *)dwUser;
timer->timerProc();
}
BOOL CMMTimers::startTimer(UINT period,BOOL oneShot)
{
BOOL res = false;
MMRESULT result;
result = timeSetEvent(period,timerRes,internalTimerProc,(DWORD)this,oneShot ? TIME_ONESHOT : TIME_PERIODIC);
if (NULL != result)
{
timerId = (UINT)result;
res = true;
}
return res;
}
BOOL CMMTimers::stopTimer()
{
MMRESULT result;
result = timeKillEvent(timerId);
if (TIMERR_NOERROR == result)
timerId = 0;
return TIMERR_NOERROR == result;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?