![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Fast Track Visual C++ 6.0 Programming
Listing 4.3 ComboView.h and ComboView.cpp // ComboView.h : interface of the CComboView class // ///////////////////////////////////////////////////////////////////////////// #if !defined(AFX_COMBOVIEW_H__D36DAA6D_9E10_11D1_887F_D42B07C10710__INCLUDED_) #define AFX_COMBOVIEW_H__D36DAA6D_9E10_11D1_887F_D42B07C10710__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 class CComboView : public CView { protected: // create from serialization only CComboView(); DECLARE_DYNCREATE(CComboView) int m_FigureType; // Attributes public: CComboDoc* GetDocument(); // Operations public: // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CComboView) 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 ~CComboView(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: //{{AFX_MSG(CComboView) afx_msg void OnDrawFigure(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; #ifndef _DEBUG // debug version in ComboView.cpp inline CComboDoc* CComboView::GetDocument() { return (CComboDoc*)m_pDocument; } #endif ///////////////////////////////////////////////////////////////////////////// //{{AFX_INSERT_LOCATION}} // Microsoft Visual C++ will insert additional declarations immediately before the previous line. #endif // !defined(AFX_COMBOVIEW_H__D36DAA6D_9E10_11D1_887F_D42B07C10710__INCLUDED_) // ComboView.cpp : implementation of the CComboView class // #include stdafx.h #include Combo.h #include MainFrm.h #include ComboDoc.h #include ComboView.h #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CComboView IMPLEMENT_DYNCREATE(CComboView, CView) BEGIN_MESSAGE_MAP(CComboView, CView) //{{AFX_MSG_MAP(CComboView) ON_COMMAND(ID_DRAW, OnDrawFigure) //}}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() ///////////////////////////////////////////////////////////////////////////// // CComboView construction/destruction CComboView::CComboView() { m_FigureType = 0; // TODO: add construction code here } CComboView::~CComboView() { } BOOL CComboView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CComboView drawing void CComboView::OnDraw(CDC* pDC) { CComboDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); switch(m_FigureType){ case 0: pDC->Ellipse(200, 50, 400, 250); break; case 1: pDC->Rectangle(200, 50, 400, 250); break; case 2: pDC->RoundRect(200, 50, 400, 250, 20, 20); break; } // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CComboView printing BOOL CComboView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CComboView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CComboView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CComboView diagnostics #ifdef _DEBUG void CComboView::AssertValid() const { CView::AssertValid(); } void CComboView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CComboDoc* CComboView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CComboDoc))); return (CComboDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CComboView message handlers void CComboView::OnDrawFigure() { m_FigureType = ((CMainFrame*) GetParent())->GetItemNumber(); Invalidate(); // TODO: Add your command handler code here } Whats AheadIn the next chapter, we forge ahead, bringing together what weve seen in the last few chapters as we build a real-world application. As we dig deeper into more advanced topics, many new topics, from file handling to working with the clipboard, will come up.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |