class CPractice3_2View : public CView
{
...
// Generated message map functions
protected:
//{{AFX_MSG(CPractice3_2View)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDestroy();
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
// {
private:
BOOL m_bTimerRun;
CString m_strTimer;
// }
};
...
BEGIN_MESSAGE_MAP(CPractice3_2View, CView)
//{{AFX_MSG_MAP(CPractice3_2View)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_TIMER()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
...
END_MESSAGE_MAP()
...
void CPractice3_2View::OnDraw(CDC* pDC)
{
CPractice3_2Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CRect rect;
GetClientRect(&rect); //윈도우 클라이언트 영역을 얻는다.
pDC->DrawText(m_strTimer, rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
}
...
int CPractice3_2View::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
...
// TODO: Add your specialized creation code here
// {
m_bTimerRun = FALSE;
// }
return 0;
}
void CPractice3_2View::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
if (m_bTimerRun)
KillTimer(0); //타이머 해제
}
void CPractice3_2View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
// {
... m_strTimer ...
Invalidate();
// }
CView::OnTimer(nIDEvent);
}
void CPractice3_2View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// {
if (!m_bTimerRun) //타이머가 동작중이 아닐때 메시지 박스 출력
{
SetTimer(0, 1000, NULL); //타이머 설정
m_bTimerRun = TRUE; //타이머 동작 => true
}
// }
CView::OnLButtonDown(nFlags, point);
}
void CPractice3_2View::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// {
if (m_bTimerRun)
{
KillTimer(0); //타이머 해제
m_bTimerRun=FALSE; //타이머 동작 =>false
}
// }
CView::OnRButtonDown(nFlags, point);
}