按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
附錄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