기.
¶
Project -> Settings -> Link -> Object/library modules: winmm.lib
¶
StdAfx.h ...
~cpp
.
.
.
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#include <mmsystem.h>
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
.
.
.
¶
~cpp
void CALLBACK TimerProc(UINT uID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
CMMTimerView *pView = (CMMTimerView*)dwUser;
pView->PostMessage(WM_USER);
}
¶
~cpp
int CMMTimerView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
m_TimerID = timeSetEvent(1, 0, TimerProc, (DWORD)this, TIME_PERIODIC);
return 0;
}
void CMMTimerView::OnDestroy()
{
CView::OnDestroy();
timeKillEvent(m_TimerID);
}
¶
WM_USER
~cpp
BEGIN_MESSAGE_MAP(CMMTimerView, CView)
//{{AFX_MSG_MAP(CMMTimerView)
.
.
//}}AFX_MSG_MAP
.
.
ON_MESSAGE(WM_USER, OnMMTimer)
END_MESSAGE_MAP()
~cpp
class CMMTimerView : public CView
{
.
.
.
// Generated message map functions
protected:
//{{AFX_MSG(CMMTimerView)
.
.
//}}AFX_MSG
afx_msg LRESULT OnMMTimer(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
};
~cpp
LRESULT CMMTimerView::OnMMTimer(WPARAM wParam, LPARAM lParam)
{
.
.
.
return 0;
}










