U E D R , A S I H C RSS

5인용C++스터디/타이머보충

No older revisions available

No older revisions available



멀티미디어 타이머 사용하기.

첫번째

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;
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:19
Processing time 0.0278 sec