友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!
深入浅出MFC第2版(PDF格式)-第90部分
快捷操作: 按键盘上方向键 ← 或 → 可快速上下翻页 按键盘上的 Enter 键可回到本书目录页 按键盘上方向键 ↑ 可回到本页顶部! 如果本书没有阅读完,想下次继续接着阅读,可使用上方 "收藏到我的浏览器" 功能 和 "加入书签" 功能!
#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 the drawing of individual strokes to
#0060 // CStroke::DrawStroke()。
#0061 CTypedPtrList& strokeList = pDoc…》m_strokeList;
#0062 POSITION pos = strokeList。GetHeadPosition();
#0063 while (pos != NULL)
#0064 {
#0065 CStroke* pStroke = strokeList。GetNext(pos);
#0066 pStroke…》DrawStroke(pDC);
#0067 }
#0068 }
#0069
#0070 ///////////////////////////////////////////////////////////////
#0071 // CScribbleView printing
#0072
#0073 BOOL CScribbleView::OnPreparePrinting(CPrintInfo* pInfo)
#0074 {
#0075 // default preparation
#0076 return DoPreparePrinting(pInfo);
490
…………………………………………………………Page 553……………………………………………………………
第8章 Document…View 深入探討
#0077 }
#0078
#0079 void CScribbleView::OnBeginPrinting(CDC* /*pDC*/; CPrintInfo* /*pInfo*/)
#0080 {
#0081 // TODO: add extra initialization before printing
#0082 }
#0083
#0084 void CScribbleView::OnEndPrinting(CDC* /*pDC*/; CPrintInfo* /*pInfo*/)
#0085 {
#0086 // TODO: add cleanup after printing
#0087 }
#0088
#0089 /////////////////////////////////////////////////////////////////
#0090 // CScribbleView diagnostics
#0091
#0092 #ifdef _DEBUG
#0093 void CScribbleView::AssertValid() const
#0094 {
#0095 CView::AssertValid();
#0096 }
#0097
#0098 void CScribbleView::Dump(CDumpContext& dc) const
#0099 {
#0100 CView::Dump(dc);
#0101 }
#0102
#0103 CScribbleDoc* CScribbleView::GetDocument() // non…debug version is inline
#0104 {
#0105 ASSERT(m_pDocument…》IsKindOf(RUNTIME_CLASS(CScribbleDoc)));
#0106 return (CScribbleDoc*)m_pDocument;
#0107 }
#0108 #endif //_DEBUG
#0109
#0110 ////////////////////////////////////////////////////////////////
#0111 // CScribbleView message handlers
#0112
#0113 void CScribbleView::OnLButtonDown(UINT; CPoint point)
#0114 {
#0115 // Pressing the mouse button in the view window starts a new stroke
#0116
#0117 m_pStrokeCur = GetDocument()…》NewStroke();
#0118 // Add first point to the new stroke
#0119 m_pStrokeCur…》m_pointArray。Add(point);
#0120
#0121 SetCapture(); // Capture the mouse until button up。
#0122 m_ptPrev = point; // Serves as the MoveTo() anchor point
#0123 // for the LineTo() the next point;
#0124 // as the user drags the mouse。
491
…………………………………………………………Page 554……………………………………………………………
第篇 深入 MFC 程式設計
#0125
#0126 return;
#0127 }
#0128
#0129 void CScribbleView::OnLButtonUp(UINT; CPoint point)
#0130 {
#0131 // Mouse button up is interesting in the Scribble application
#0132 // only if the user is currently drawing a new stroke by dragging
#0133 // the captured mouse。
#0134
#0135 if (GetCapture() != this)
#0136 return; // If this window (view) didn't capture the mouse;
#0137 // then the user isn't drawing in this window。
#0138
#0139 CScribbleDoc* pDoc = GetDocument();
#0140
#0141 CClientDC dc(this);
#0142
#0143 CPen* pOldPen = dc。SelectObject(pDoc…》GetCurrentPen());
#0144 dc。MoveTo(m_ptPrev);
#0145 dc。LineTo(point);
#0146 dc。SelectObject(pOldPen);
#0147 m_pStrokeCur…》m_pointArray。Add(point);
#0148
#0149 ReleaseCapture(); // Release the mouse capture established at
#0150 // the beginning of the mouse drag。
#0151 return;
#0152 }
#0153
#0154 void CScribbleView::OnMouseMove(UINT; CPoint point)
#0155 {
#0156 // Mouse movement is interesting in the Scribble application
#0157 // only if the user is currently drawing a new stroke by dragging
#0158 // the captured mouse。
#0159
#0160 if (GetCapture() != this)
#0161 return; // If this window (view) didn't capture the mouse;
#0162 // then the user isn't drawing in this window。
#0163
#0164 CClientDC dc(this);
#0165 m_pStrokeCur…》m_pointArray。Add(point);
#0166
#0167 // Draw a line from the previous detected point in the mouse
#0168 // drag to the
快捷操作: 按键盘上方向键 ← 或 → 可快速上下翻页 按键盘上的 Enter 键可回到本书目录页 按键盘上方向键 ↑ 可回到本页顶部!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!