友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!
深入浅出MFC第2版(PDF格式)-第160部分
快捷操作: 按键盘上方向键 ← 或 → 可快速上下翻页 按键盘上的 Enter 键可回到本书目录页 按键盘上方向键 ↑ 可回到本页顶部! 如果本书没有阅读完,想下次继续接着阅读,可使用上方 "收藏到我的浏览器" 功能 和 "加入书签" 功能!
#0037 virtual ~CScribbleView();
#0038 #ifdef _DEBUG
#0039 virtual void AssertValid() const;
#0040 virtual void Dump(CDumpContext& dc) const;
#0041 #endif
#0042
#0043 protected:
#0044
893
…………………………………………………………Page 956……………………………………………………………
第五篇 附錄
#0045 // Generated message map functions
#0046 protected:
#0047 //{{AFX_MSG(CScribbleView)
#0048 afx_msg void OnLButtonDown(UINT nFlags; CPoint point);
#0049 afx_msg void OnLButtonUp(UINT nFlags; CPoint point);
#0050 afx_msg void OnMouseMove(UINT nFlags; CPoint point);
#0051 //}}AFX_MSG
#0052 DECLARE_MESSAGE_MAP()
#0053 };
#0054
#0055 #ifndef _DEBUG // debug version in ScribVw。cpp
#0056 inline CScribbleDoc* CScribbleView::GetDocument()
#0057 { return (CScribbleDoc*)m_pDocument; }
#0058 #endif
SCRIBBLEVIEW。CPP
#0001 #include 〃stdafx。h〃
#0002 #include 〃Scribble。h〃
#0003
#0004 #include 〃ScribDoc。h〃
#0005 #include 〃ScribVw。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; CScrollView)
#0017
#0018 BEGIN_MESSAGE_MAP(CScribbleView; CScrollView)
#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()
#0029
894
…………………………………………………………Page 957……………………………………………………………
附錄B Scribble Step5 完整原始碼
#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 // Get the invalidated rectangle of the view; or in the case
#0060 // of printing; the clipping region of the printer dc。
#0061 CRect rectClip;
#0062 CRect rectStroke;
#0063 pDC…》GetClipBox(&rectClip);
#0064 pDC…》LPtoDP(&rectClip);
#0065 rectClip。InflateRect(1; 1); // avoid rounding to nothing
#0066
#0067 // Note: CScrollView::OnPaint() will have already adjusted the
#0068 // viewport origin before calling OnDraw(); to reflect the
#0069 // currently scrolled position。
#0070
#0071 // The view delegates the drawing of individual strokes to
#0072 // CStroke::DrawStroke()。
#0073 CTypedPtrList& strokeList = pDoc…》m_strokeList;
#0074 POSITION pos = strokeList。GetHeadPosition();
#0075 while (pos != NULL)
895
…………………………………………………………Page 958……………………………………………………………
第五篇 附錄
#0076 {
#0077 CStroke* pStroke = strokeList。GetNext(pos);
#0078 rectStroke = pStroke…》GetBoundingRect();
#0079 pDC…》LPtoDP(&rectStroke);
#0080 rectStroke。InflateRect(1; 1); // avoid rounding to nothing
#0081 if (!rectStroke。IntersectRect(&rectStroke; &rectClip))
#0082 continue;
#0083 pStroke…》DrawStroke(pDC);
#0084 }
#0085 }
#0086
#0087 /////////////////////////////////////////////////////////////////
#0088 // CScribbleView printing
#0089
#0090 BOOL CScribbleView::OnPreparePrinting(CPrintInfo* pInfo)
#0091 {
#0092 pInfo…》SetMaxPage(2); // the document is two pages long:
#0093 // the first page is the title page
#0094 // the second is the drawing
#0095 BOOL bRet = DoPreparePrinting(pInfo); // default preparation
#0096 pInfo…》m_nNumPreviewPages = 2; // Preview 2 pages at a time
#0097 // Set this value after calling DoPreparePrinting to override
#0098 // value read from 。INI file
#0099 return bRet;
#0100 }
#0101
#0102 void CScribbleView::OnBeginPrinting(CDC* /*pDC*/; CPrintInfo* /*pInfo*/)
#0103 {
#0104 // TODO: add extra initialization before printing
#0105 }
#0106
#0107 void CScribbleView::OnEndPrinting(CDC* /*pDC*/; CPrintInfo* /*pInfo*/)
#0108 {
#0109 // TODO: add cleanup after printing
#0110 }
#0111
#0112 ///////////////////////////////////////////////////////////////
#0113 // CScribbleView diagnostics
#0114
#0115 #ifdef _DEBUG
#0116 void CScribbleView::AssertValid() const
#0117 {
#0118 CScrollView::AssertValid();
#0119 }
#0120
#0121 void CScribbleView::Dump(CDumpContext& dc) const
896
…………………………………………………………Page 959……………………………………………………………
附錄B Scribble Step5 完整原始碼
#0122 {
#0123 CScrollView::Dump(dc);
#0124 }
#0125
#0126 CScribbleDoc* CScribbleView::GetDocument() // non…debug version is inline
#0127 {
#0128 ASSERT(m_pDocument…》IsKindOf(RUNTIME_CLASS(CScribbleDoc)));
#0129 return (CScribbleDoc*)m_pDocument;
#0130 }
#0131 #endif //_DEBUG
#0132
#0133 /////////////////////////////////////////////////////////////////
#0134 // CScribbleView message handlers
#0135
#0136 void CScribbleView::OnLButtonDown(UINT; CPoint point)
#0137 {
#0138 // Pressing the mouse button in the view window starts a new stroke
#0139
#0140 // CScrollView changes the viewport origin and mapping mode。
#0141 // It's necessary to convert the point from device coordinates
#0142 // to logical coordinates; such as are stored in the document。
#0143 CClientDC dc(this);
#0144 OnPrepareDC(&dc);
#0145 dc。DPtoLP(&point);
#0146
#0147 m_pStrokeCur = GetDocument()…》NewStroke();
#0148 // Add first point to the new stroke
#0149 m_pStrokeCur…》m_pointArray。Add(point);
#0150
#0151 SetCapture(); // Capture the mouse until button up。
#0152 m_ptPrev = point; // Serves as the MoveTo() anchor point for the
#0153 // LineTo() the next point; as the user drags the
#0154 // mouse。
#0155
#0156 return;
#0157 }
#0158
#0159 void CScribbleView::OnLButtonUp(UINT; CPoint point)
#0160 {
#0161 // Mouse button up is interesting in the Scribble application
#0162 // only if the user is currently drawing a new stroke by dragging
#0163 // the captured mouse。
#0164
#0165 if (GetCapture() != this)
#0166 return; // If this window (view) didn't capture the mouse;
#0167 // then the user isn't drawing in this window。
897
…………………………………………………………Page 960……………………………………………………………
第五篇 附錄
#0168
#0169 CScribbleDoc* pDoc = GetDocument();
#0170
#0171 CClientDC dc(this);
#0172
#0173 // CScrollView changes the viewport origin and mapping mode。
#0174 // It's necessary to convert the point from device coordinates
#0175 // to logical coordinates; such as are stored in the document。
#0176 OnPrepareDC(&dc); // set up mapping mode and viewport origin
#0177 dc。DPtoLP(&point);
#0178
#0179 CPen* pOldPen
快捷操作: 按键盘上方向键 ← 或 → 可快速上下翻页 按键盘上的 Enter 键可回到本书目录页 按键盘上方向键 ↑ 可回到本页顶部!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!