按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
得CScribbleDoc 的对象指针。View 可以藉此指针取得Document 的资料,然后显示。
487
…………………………………………………………Page 550……………………………………………………………
CScribbleView 的修改
以下是Step1 程序的View 的设计。其中有鼠标接口,也有资料显示功能OnDraw
SCRIBBLEV IEW 。H (阴影表示与Step0的差异)
#0001 class CScribbleView : public CView
#0002 {
#0003 protected: // create from serialization only
#0004 CScribbleView();
#0005 DECLARE_DYNCREATE(CScribbleView)
#0006
#0007 // Attributes
#0008 public:
#0009 CScribbleDoc* GetDocument();
#0010
#0011 protected:
#0012 CStroke* m_pStrokeCur; // the stroke in progress
#0013 CPoint m_ptPrev; // the last mouse pt in the stroke in progress
#0014
#0015 // Operations
#0016 public:
#0017
#0018 // Overrides
#0019 // ClassWizard generated virtual function overrides
#0020 //{{AFX_VIRTUAL(CScribbleView)
#0021 public:
#0022 virtual void OnDraw(CDC* pDC); // overridden to draw this view
#0023 virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
#0024 protected:
#0025 virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
#0026 virtual void OnBeginPrinting(CDC* pDC; CPrintInfo* pInfo);
#0027 virtual void OnEndPrinting(CDC* pDC; CPrintInfo* pInfo);
#0028 //}}AFX_VIRTUAL
#0029
#0030 // Implementation
#0031 public:
#0032 virtual ~CScribbleView();
#0033 #ifdef _DEBUG
#0034 virtual void AssertValid() const;
#0035 virtual void Dump(CDumpContext& dc) const;
#0036 #endif
#0037
#0038 protected:
#0039
488
…………………………………………………………Page 551……………………………………………………………
#0040 // Generated message map functions
#0041 protected:
#0042 //{{AFX_MSG(CScribbleView)
#0043 afx_msg void OnLButtonDown(UINT nFlags; CPoint point);
#0044 afx_msg void OnLButtonUp(UINT nFlags; CPoint point);
#0045 afx_msg void OnMouseMove(UINT nFlags; CPoint point);
#0046 //}}AFX_MSG
#0047 DECLARE_MESSAGE_MAP()
#0048 };
#0049
#0050 #ifndef _DEBUG // debug version in ScribVw。cpp
#0051 inline CScribbleDoc* CScribbleView::GetDocument()
#0052 { return (CScribbleDoc*)m_pDocument; }
#0053 #endif
SCRIBBLEV IEW 。CPP (阴影表示与Step0的差异)
#0001 #include 〃stdafx。h〃
#0002 #include 〃Scribble。h〃
#0003
#0004 #include 〃ScribbleDoc。h〃
#0005 #include 〃ScribbleView。h〃
#0006
#0007 #ifdef _DEBUG
#0008 #define new DEBUG_NEW
#0009 #undef THIS_FILE
#0010 static char THIS_FILE'' = __FILE__;
#0011 #endif
#0012
#0013 /////////////////////////////////////////////////////////////////
#0014 // CScribbleView
#0015
#0016 IMPLEMENT_DYNCREATE(CScribbleView; CView)
#0017
#0018 BEGIN_MESSAGE_MAP(CScribbleView; CView)
#0019 //{{AFX_MSG_MAP(CScribbleView)
#0020 ON_WM_LBUTTONDOWN()
#0021 ON_WM_LBUTTONUP()
#0022 ON_WM_MOUSEMOVE()
#0023 //}}AFX_MSG_MAP
#0024 // Standard printing mands
#0025 ON_MAND(ID_FILE_PRINT; CView::OnFilePrint)
#0026 ON_MAND(ID_FILE_PRINT_DIRECT; CView::OnFilePrint)
#0027 ON_MAND(ID_FILE_PRINT_PREVIEW; CView::OnFilePrintPreview)
#0028 END_MESSAGE_MAP()
489
…………………………………………………………Page 552……………………………………………………………
第篇 深入 MFC 程式設計
#0029
#0030 ///////////////////////////////////////////////////////////////
#0031 // CScribbleView construction/destruction
#0032
#0033 CScribbleView::CScribbleView()
#0034 {
#0035 // TODO: add construction code here
#0036
#0037 }
#0038
#0039 CScribbleView::~CScribbleView()
#0040 {
#0041 }
#0042
#0043 BOOL CScribbleView::PreCreateWindow(CREATESTRUCT& cs)
#0044 {
#0045 // TODO: Modify the Window class or styles here by modifying
#0046 // the CREATESTRUCT cs
#0047
#0048 return CView::PreCreateWindow(cs);
#0049 }
#0050
#0051 /////////////////////////////////////////////////////////////////
#0052 // CScribbleView drawing
#0053
#0054 void CScribbleView::OnDraw(CDC* pDC)
#0055 {
#0056 CScribbleDoc* pDoc = GetDocument();
#0057 ASSERT_VALID(pDoc);
#0058
#0059 // The view delegates