(2014.10.29) MFC - Multimedia timer 사용 방법
MFC에서 제공하는 OnTimer() 는 54msec보다 적은 값의 time을 생성하지 못한다.
이 경우 Multimedia timer를 이용하면 msec 단위의 timer를 생성할 수 있다.
- Multimedia timer는 자체적으로 thread를 생성, 동작한다.
> 테스트 환경
. OS: Windows 7 Ultimate K 64bits
. SDK: Visual studio 2013 professional
. 참고 URL: http://blog.naver.com/snrnsrk06/100188374706
(1) Project folder에 아래의 파일을 복사한다.
(2) Header 파일에 Dialog class를 생성시키고 CMMTimerListener 를 상속받는다.
> CXXXDlg.h
#include "MMTimer.h"
class CToolsIvnDlg : public CDialogEx, public CMMTimerListener
{
private:
CMMTimer m_Timer;
UINT m_MaxResolution;
void Update(CMMTimer &Timer);
}
(3) cpp 파일에 아래와 같이 code를 추가한다.
> CXXXDlg.cpp
BOOL CToolsIvnDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: Add extra initialization here
// MMTimer
m_Timer.AttachListener(*(CMMTimerListener*)this);
TIMECAPS TimeCaps;
m_Timer.GetDevCaps(&TimeCaps);
m_MaxResolution = TimeCaps.wPeriodMax;
//m_Timer.Start(20, m_MaxResolution);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CToolsIvnDlg::MMTimer_Start()
{
m_Timer.Start(m_TxInterval, m_MaxResolution); // m_TxInterval : timer 호출 주기, 단위: msec
}
BOOL CToolsIvnDlg::MMTimer_Stop()
{
m_Timer.Stop();
}
// 설정된 time 마다 호출할 함수
void CToolsIvnDlg::Update(CMMTimer &Timer)
{
//debug_printf("test \r\n");
SendOBDFrame(); // 실행하고자 하는 함수 작성
}
void CToolsIvnDlg::OnDestroy()
{
CDialogEx::OnDestroy();
// TODO: Add your message handler code here
// MMTimer
m_Timer.Stop();
}
'Dev' 카테고리의 다른 글
Source Insight에서 CLF(Custom Language File) 추가하기 (0) | 2014.12.22 |
---|---|
Source Insight - Bookmark 매크로 생성 및 단축기 설정하기 (0) | 2014.10.30 |
PICKIT3 장비에 Firmware download 하기 (programmer to go 기능) (0) | 2014.10.21 |
Multi compiler에서 s19 파일 생성, ROM/RAM size 표시 방법 (0) | 2014.10.09 |
Visual Studio 2013에서 MSB8031 error 해결방법 (멀티바이트 MFC 라이브러리) (0) | 2014.09.27 |