按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
#0212 {
#0213 CPenWidthsDlg dlg;
#0214 // Initialize dialog data
#0215 dlg。m_nThinWidth = m_nThinWidth;
#0216 dlg。m_nThickWidth = m_nThickWidth;
891
…………………………………………………………Page 954……………………………………………………………
第五篇 附錄
#0217
#0218 // Invoke the dialog box
#0219 if (dlg。DoModal() == IDOK)
#0220 {
#0221 // retrieve the dialog data
#0222 m_nThinWidth = dlg。m_nThinWidth;
#0223 m_nThickWidth = dlg。m_nThickWidth;
#0224
#0225 // Update the pen that is used by views when drawing new strokes;
#0226 // to reflect the new pen width definitions for 〃thick〃 and 〃thin〃。
#0227 ReplacePen();
#0228 }
#0229 }
#0230
#0231 void CStroke::FinishStroke()
#0232 {
#0233 // Calculate the bounding rectangle。 It's needed for smart
#0234 // repainting。
#0235
#0236 if (m_pointArray。GetSize()==0)
#0237 {
#0238 m_rectBounding。SetRectEmpty();
#0239 return;
#0240 }
#0241 CPoint pt = m_pointArray'0';
#0242 m_rectBounding = CRect(pt。x; pt。y; pt。x; pt。y);
#0243
#0244 for (int i=1; i 《 m_pointArray。GetSize(); i++)
#0245 {
#0246 // If the point lies outside of the accumulated bounding
#0247 // rectangle; then inflate the bounding rect to include it。
#0248 pt = m_pointArray'i';
#0249 m_rectBounding。left = min(m_rectBounding。left; pt。x);
#0250 m_rectBounding。right = max(m_rectBounding。right; pt。x);
#0251 m_rectBounding。top = max(m_rectBounding。top; pt。y);
#0252 m_rectBounding。bottom = min(m_rectBounding。bottom; pt。y);
#0253 }
#0254
#0255 // Add the pen width to the bounding rectangle。 This is necessary
#0256 // to account for the width of the stroke when invalidating
#0257 // the screen。
#0258 m_rectBounding。InflateRect(CSize(m_nPenWidth; …(int)m_nPenWidth));
#0259 return;
#0260 }
892
…………………………………………………………Page 955……………………………………………………………
附錄B Scribble Step5 完整原始碼
SCRIBBLEVIEW。H
#0001 class CScribbleView : public CScrollView
#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 virtual void OnInitialUpdate();
#0025 protected:
#0026 virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
#0027 virtual void OnBeginPrinting(CDC* pDC; CPrintInfo* pInfo);
#0028 virtual void OnEndPrinting(CDC* pDC; CPrintInfo* pInfo);
#0029 virtual void OnUpdate(CView* pSender; LPARAM lHint; CObject* pHint);
#0030 virtual void OnPrint(CDC* pDC; CPrintInfo* pInfo);
#0031 //}}AFX_VIRTUAL
#0032
#0033 // Implementation
#0034 public:
#0035 void PrintTitlePage(CDC* pDC; CPrintInfo* pInfo);
#0036 void PrintPageHeader(CDC* pDC; CPrintInfo* pInfo; CString& strHeader);
#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 完整原始碼
#0