#include <mmsystem.h>
#pragma comment(lib, "winmm")
class CMMTimerDlg : public CDialog
{
// {
UINT m_nMs;
UINT m_TimerID;
BOOL MM_Toggle;
// }
// Construction
public:
CMMTimerDlg(CWnd* pParent = NULL); // standard constructor
...
// Generated message map functions
//{{AFX_MSG(CMMTimerDlg)
...
afx_msg void OnDestroy();
afx_msg void OnBtnMm();
//}}AFX_MSG
// {
afx_msg void OnMM(WPARAM wParam, LPARAM lParam);
// }
DECLARE_MESSAGE_MAP()
};
// {
#include <mmsystem.h>
#define UM_MYMSGMM (WM_USER + 1)
// }
BEGIN_MESSAGE_MAP(CMMTimerDlg, CDialog)
//{{AFX_MSG_MAP(CMMTimerDlg)
...
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BTN_MM, OnBtnMm)
//}}AFX_MSG_MAP
// {
ON_MESSAGE(UM_MYMSGMM, OnMM )
// }
END_MESSAGE_MAP()
...
BOOL CMMTimerDlg::OnInitDialog()
{
...
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// {
m_nMs = 1000;
m_TimerID = 0;
TIMECAPS tc;
timeGetDevCaps(&tc,sizeof(TIMECAPS));
if(m_nMs < tc.wPeriodMin)
m_nMs = tc.wPeriodMin;
else if(nMs > tc.wPeriodMax)
m_nMs = tc.wPeriodMax;
timeBeginPeriod(m_nMs);
MM_Toggle = FALSE;
// }
return TRUE; // return TRUE unless you set the focus to a control
}
void CMMTimerDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
// {
if( m_TimerID != 0)
timeKillEvent(m_TimerID);
timeEndPeriod(m_nMs);
// }
}
...
// {
//멀티미디어 타이머 콜백 함수
void CALLBACK TimerProc(UINT uiID, UINT uiMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
CMMTimerDlg *pDlg = (CMMTimerDlg *)AfxGetMainWnd();
pDlg->SendMessage(UM_MYMSGMM, 0, 0);
}
// }
void CMMTimerDlg::OnBtnMm()
{
// TODO: Add your control notification handler code here
if (MM_Toggle == FALSE) {
m_TimerID = timeSetEvent(m_nMs, 0, &TimerProc, (DWORD)this, TIME_PERIODIC);// 멀티미디어 타이머 설정
MM_Toggle = TRUE; } else { timeKillEvent(m_TimerID);//멀티미디어 타이머 죽임
m_TimerID = 0;
MM_Toggle = FALSE; }
}
void CMMTimerDlg::OnMM(WPARAM wParam, LPARAM lParam) {
...
}