《深入浅出MFC第2版(PDF格式)》第294章


#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 = dc。SelectObject(pDoc…》GetCurrentPen()); 
#0180 dc。MoveTo(m_ptPrev); 
#0181 dc。LineTo(point); 
#0182 dc。SelectObject(pOldPen); 
#0183 m_pStrokeCur…》m_pointArray。Add(point); 
#0184 
#0185 // Tell the stroke item that we"re done adding points to it。 
#0186 // This is so it can finish puting its bounding rectangle。 
#0187 m_pStrokeCur…》FinishStroke(); 
#0188 
#0189 // Tell the other views that this stroke has been added 
#0190 // so that they can invalidate this stroke"s area in their 
#0191 // client area。 
#0192 pDoc…》UpdateAllViews(this; 0L; m_pStrokeCur); 
#0193 
#0194 ReleaseCapture(); // Release the mouse capture established at 
#0195 // the beginning of the mouse drag。 
#0196 return; 
#0197 } 
#0198 
#0199 void CScribbleView::OnMouseMove(UINT; CPoint point) 
#0200 { 
#0201 // Mouse movement is interesting in the Scribble application 
#0202 // only if the user is currently drawing a new stroke by dragging 
#0203 // the captured mouse。 
#0204 
#0205 if (GetCapture() != this) 
#0206 return; // If this window (view) didn"t capture the mouse; 
#0207 // then the user isn"t drawing in this window。 
#0208 
#0209 CClientDC dc(this); 
#0210 // CScrollView changes the viewport origin and mapping mode。 
#0211 // It"s necessary to convert the point from device coordinates 
#0212 // to logical coordinates; such as are stored in the document。 
#0213 OnPrepareDC(&dc); 
898 
…………………………………………………………Page 961……………………………………………………………
附錄B Scribble Step5 完整原始碼 
#0214 dc。DPtoLP(&point); 
#0215 
#0216 m_pStrokeCur…》m_pointArray。Add(point); 
#0217 
#0218 // Draw a line from the previous detected point in the mouse 
#0219 // drag to the current point。 
#0220 CPen* pOldPen = dc。SelectObject(GetDocument()…》GetCurrentPen()); 
#0221 dc。MoveTo(m_ptPrev); 
#0222 dc。LineTo(point); 
#0223 dc。SelectObject(pOldPen); 
#0224 m_ptPrev = point; 
#0225 return; 
#0226 } 
#0227 
#0228 void CScribbleView::OnUpdate(CView* /* pSender */; LPARAM /* lHint */; 
#0229 CObject* pHint) 
#0230 { 
#0231 // The document has informed this view that some data has changed。 
#0232 
#0233 if (pHint != NULL) 
#0234 { 
#0235 if (pHint…》IsKindOf(RUNTIME_CLASS(CStroke))) 
#0236 { 
#0237 // The hint is that a stroke as been added (or changed)。 
#0238 // So; invalidate its rectangle。 
#0239 CStroke* pStroke = (CStroke*)pHint; 
#0240 CClientDC dc(this); 
#0241 OnPrepareDC(&dc); 
#0242 CRect rectInvalid = pStroke…》GetBoundingRect(); 
#0243 dc。LPtoDP(&rectInvalid); 
#0244 InvalidateRect(&rectInvalid); 
#0245 return; 
#0
小说推荐
返回首页返回目录