Programming/MFC
Example : StatSpltWnd
부풍
2009. 8. 29. 11:40
Project 생성
- SDI
- 분할 창 선택 안함
StatSpltWndDoc 클래스 추가
class CStatSpltWndDoc : public CDocument { protected: // serialization에서만 만들어집니다. CStatSpltWndDoc(); DECLARE_DYNCREATE(CStatSpltWndDoc) // 특성 public: CString m_String; /* 추가 */
WM_CHAR 메시지 처리
void CStatSpltWndView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { CStatSpltWndDoc *pDoc = GetDocument(); pDoc->m_String += (char)nChar; pDoc->UpdateAllViews(NULL); /* 인자를 this로도 해본다. */ }
OnDraw
void CStatSpltWndView::OnDraw(CDC* pDC) { CStatSpltWndDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO: 여기에 원시 데이터에 대한 그리기 코드를 추가합니다. pDC->TextOut(0, 0, pDoc->m_String, pDoc->m_String.GetLength()); }
CHexView 생성
HexView.h
#pragma once #include "StatSpltWndDoc.h" // CHexView 뷰입니다. class CHexView : public CView { DECLARE_DYNCREATE(CHexView) protected: CHexView(); // 동적 만들기에 사용되는 protected 생성자입니다. virtual ~CHexView(); public: virtual void OnDraw(CDC* pDC); // 이 뷰를 그리기 위해 재정의되었습니다. #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: DECLARE_MESSAGE_MAP() public: virtual CStatSpltWndDoc* GetDocument(); /* 추가 */ };
HexView.cpp
// HexView.cpp : 구현 파일입니다. // #include "stdafx.h" #include "StatSpltWnd.h" #include "HexView.h" #include ".\hexview.h" void CHexView::OnDraw(CDC* pDC) { CStatSpltWndDoc* pDoc = GetDocument(); // TODO: 여기에 그리기 코드를 추가합니다. CString OutLine, str; int n; for(int i = 0; i < pDoc->m_String.GetLength(); i++) { n = pDoc->m_String[i] & 0x00ff; str.Format("%02x ", n); OutLine += str; } pDC->TextOut(0, 0, OutLine); } CStatSpltWndDoc* CHexView::GetDocument() { return (CStatSpltWndDoc*)m_pDocument; }
CMainFrame 수정
MainFrame.h
class CMainFrame : public CFrameWnd { // ~~~~ protected: CSplitterWnd m_wndSplitter; };
CMainFrame::OnCreateClient 재정의
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) { m_wndSplitter.CreateStatic(this, 1, 2); m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CStatSpltWndView), CSize(200, 200), pContext); m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CHexView), CSize(200, 200), pContext); SetActiveView((CView*)m_wndSplitter.GetPane(0, 0)); return TRUE; }