View 클래스의 수정된 소스코드부분만 올립니돠. 많은 참고 바람돠.
(학교 리포트 제출용으로 작성된 코드입니다.^^;)
/*****************************************/ // MerongView.h : interface of the CMerongView class // ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_MERONGVIEW_H__80F1944E_A1D8_11D3_8E46_00C02680254A__INCLUDED_) #define AFX_MERONGVIEW_H__80F1944E_A1D8_11D3_8E46_00C02680254A__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CMerongView : public CView { protected: // create from serialization only CMerongView(); DECLARE_DYNCREATE(CMerongView) // Attributes public: CMerongDoc* GetDocument(); TEXTMETRIC text; bool m_flag1, m_flag2, m_flag3, m_flag4, m_flag5; // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMerongView) public: virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: virtual BOOL OnPreparePrinting(CPrintInfo* pInfo); virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo); //}}AFX_VIRTUAL // Implementation public: virtual ~CMerongView(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: //{{AFX_MSG(CMerongView) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnTimer(UINT nIDEvent); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; #ifndef _DEBUG // debug version in MerongView.cpp inline CMerongDoc* CMerongView::GetDocument() { return (CMerongDoc*)m_pDocument; } #endif ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_MERONGVIEW_H__80F1944E_A1D8_11D3_8E46_00C02680254A__INCLUDED_) /*****************************************/ // MerongView.cpp : implementation of the CMerongView class // #include "stdafx.h" #include "Merong.h" #include "MerongDoc.h" #include "MerongView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMerongView IMPLEMENT_DYNCREATE(CMerongView, CView) BEGIN_MESSAGE_MAP(CMerongView, CView) //{{AFX_MSG_MAP(CMerongView) ON_WM_CREATE() ON_WM_TIMER() //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMerongView construction/destruction CMerongView::CMerongView() { // TODO: add construction code here m_flag1 = true; m_flag2 = true; m_flag3 = true; m_flag4 = true; m_flag5 = true; } CMerongView::~CMerongView() { } BOOL CMerongView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CMerongView drawing void CMerongView::OnDraw(CDC* pDC) { CMerongDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDC->GetTextMetrics(&text); // TODO: add draw code for native data here pDC->SetTextAlign(TA_LEFT | TA_BOTTOM); //CFont font; pDC->SetTextColor(RGB(255,0,0)); pDC->TextOut(1, pDoc->m_currently1,CString("Timer1 - 100ms")); pDC->TextOut(150, pDoc->m_currently2,CString("Timer2 - 200ms")); pDC->TextOut(300, pDoc->m_currently3,CString("Timer3 - 300ms")); pDC->TextOut(450, pDoc->m_currently4,CString("Timer4 - 400ms")); pDC->TextOut(600, pDoc->m_currently5,CString("Timer5 - 500ms")); } ///////////////////////////////////////////////////////////////////////////// // CMerongView printing BOOL CMerongView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CMerongView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CMerongView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CMerongView diagnostics #ifdef _DEBUG void CMerongView::AssertValid() const { CView::AssertValid(); } void CMerongView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CMerongDoc* CMerongView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMerongDoc))); return (CMerongDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMerongView message handlers int CMerongView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here SetTimer(1,100,NULL); SetTimer(2,200,NULL); SetTimer(3,300,NULL); SetTimer(4,400,NULL); SetTimer(5,500,NULL); return 0; } void CMerongView::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CMerongDoc *pDoc = GetDocument(); ASSERT_VALID(pDoc); CRect rect; GetClientRect(&rect); rect.top += text.tmAscent; rect.bottom += text.tmDescent; switch(nIDEvent){ case 1: if(m_flag1){ pDoc->m_currently1+=2; if(pDoc->m_currently1 >= rect.bottom) m_flag1 = false; } else{ pDoc->m_currently1-=2; if(pDoc->m_currently1 <= rect.top) m_flag1 = true; } break; case 2: if(m_flag2){ pDoc->m_currently2+=2; if(pDoc->m_currently2 >= rect.bottom) m_flag2 = false; } else{ pDoc->m_currently2-=2; if(pDoc->m_currently2 <= rect.top) m_flag2 = true; } break; case 3: if(m_flag3){ pDoc->m_currently3+=2; if(pDoc->m_currently3 >= rect.bottom) m_flag3 = false; } else{ pDoc->m_currently3-=2; if(pDoc->m_currently3 <= rect.top) m_flag3 = true; } break; case 4: if(m_flag4){ pDoc->m_currently4+=2; if(pDoc->m_currently4 >= rect.bottom) m_flag4 = false; } else{ pDoc->m_currently4-=2; if(pDoc->m_currently4 <= rect.top) m_flag4 = true; } break; case 5: if(m_flag5){ pDoc->m_currently5+=2; if(pDoc->m_currently5 >= rect.bottom) m_flag5 = false; } else{ pDoc->m_currently5-=2; if(pDoc->m_currently5 <= rect.top) m_flag5 = true; } break; } Invalidate(FALSE); CView::OnTimer(nIDEvent); }
(학교 리포트 제출용으로 작성된 코드입니다.^^;)
/*****************************************/ // MerongView.h : interface of the CMerongView class // ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_MERONGVIEW_H__80F1944E_A1D8_11D3_8E46_00C02680254A__INCLUDED_) #define AFX_MERONGVIEW_H__80F1944E_A1D8_11D3_8E46_00C02680254A__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CMerongView : public CView { protected: // create from serialization only CMerongView(); DECLARE_DYNCREATE(CMerongView) // Attributes public: CMerongDoc* GetDocument(); TEXTMETRIC text; bool m_flag1, m_flag2, m_flag3, m_flag4, m_flag5; // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMerongView) public: virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: virtual BOOL OnPreparePrinting(CPrintInfo* pInfo); virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo); //}}AFX_VIRTUAL // Implementation public: virtual ~CMerongView(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: //{{AFX_MSG(CMerongView) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnTimer(UINT nIDEvent); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; #ifndef _DEBUG // debug version in MerongView.cpp inline CMerongDoc* CMerongView::GetDocument() { return (CMerongDoc*)m_pDocument; } #endif ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_MERONGVIEW_H__80F1944E_A1D8_11D3_8E46_00C02680254A__INCLUDED_) /*****************************************/ // MerongView.cpp : implementation of the CMerongView class // #include "stdafx.h" #include "Merong.h" #include "MerongDoc.h" #include "MerongView.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMerongView IMPLEMENT_DYNCREATE(CMerongView, CView) BEGIN_MESSAGE_MAP(CMerongView, CView) //{{AFX_MSG_MAP(CMerongView) ON_WM_CREATE() ON_WM_TIMER() //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMerongView construction/destruction CMerongView::CMerongView() { // TODO: add construction code here m_flag1 = true; m_flag2 = true; m_flag3 = true; m_flag4 = true; m_flag5 = true; } CMerongView::~CMerongView() { } BOOL CMerongView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CMerongView drawing void CMerongView::OnDraw(CDC* pDC) { CMerongDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDC->GetTextMetrics(&text); // TODO: add draw code for native data here pDC->SetTextAlign(TA_LEFT | TA_BOTTOM); //CFont font; pDC->SetTextColor(RGB(255,0,0)); pDC->TextOut(1, pDoc->m_currently1,CString("Timer1 - 100ms")); pDC->TextOut(150, pDoc->m_currently2,CString("Timer2 - 200ms")); pDC->TextOut(300, pDoc->m_currently3,CString("Timer3 - 300ms")); pDC->TextOut(450, pDoc->m_currently4,CString("Timer4 - 400ms")); pDC->TextOut(600, pDoc->m_currently5,CString("Timer5 - 500ms")); } ///////////////////////////////////////////////////////////////////////////// // CMerongView printing BOOL CMerongView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CMerongView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CMerongView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CMerongView diagnostics #ifdef _DEBUG void CMerongView::AssertValid() const { CView::AssertValid(); } void CMerongView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CMerongDoc* CMerongView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMerongDoc))); return (CMerongDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMerongView message handlers int CMerongView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; // TODO: Add your specialized creation code here SetTimer(1,100,NULL); SetTimer(2,200,NULL); SetTimer(3,300,NULL); SetTimer(4,400,NULL); SetTimer(5,500,NULL); return 0; } void CMerongView::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CMerongDoc *pDoc = GetDocument(); ASSERT_VALID(pDoc); CRect rect; GetClientRect(&rect); rect.top += text.tmAscent; rect.bottom += text.tmDescent; switch(nIDEvent){ case 1: if(m_flag1){ pDoc->m_currently1+=2; if(pDoc->m_currently1 >= rect.bottom) m_flag1 = false; } else{ pDoc->m_currently1-=2; if(pDoc->m_currently1 <= rect.top) m_flag1 = true; } break; case 2: if(m_flag2){ pDoc->m_currently2+=2; if(pDoc->m_currently2 >= rect.bottom) m_flag2 = false; } else{ pDoc->m_currently2-=2; if(pDoc->m_currently2 <= rect.top) m_flag2 = true; } break; case 3: if(m_flag3){ pDoc->m_currently3+=2; if(pDoc->m_currently3 >= rect.bottom) m_flag3 = false; } else{ pDoc->m_currently3-=2; if(pDoc->m_currently3 <= rect.top) m_flag3 = true; } break; case 4: if(m_flag4){ pDoc->m_currently4+=2; if(pDoc->m_currently4 >= rect.bottom) m_flag4 = false; } else{ pDoc->m_currently4-=2; if(pDoc->m_currently4 <= rect.top) m_flag4 = true; } break; case 5: if(m_flag5){ pDoc->m_currently5+=2; if(pDoc->m_currently5 >= rect.bottom) m_flag5 = false; } else{ pDoc->m_currently5-=2; if(pDoc->m_currently5 <= rect.top) m_flag5 = true; } break; } Invalidate(FALSE); CView::OnTimer(nIDEvent); }