11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8. DC, Pen, Brush and Palette<br />

If m_nCurrentPt is 0, this means it is the first control point. In this case, we do not need to draw or<br />

erase anything. However, we need to set the window capture.<br />

If m_nCurrentPt is not 0, we need to erase the previous curve, record the new point, assign its value to<br />

the rest points (This is for the convenience of drawing curve outline, because when we draw a curve, we<br />

always need four control points), and draw the curve outline.<br />

Then the implementation of CGDIView::OnMouseMove(…) becomes easy. We just need to check if there<br />

is an existing curve outline. If so, we need to erase it before drawing a new curve outline. Otherwise we just<br />

draw the curve outline directly and set m_bNeedErase flag:<br />

void CGDIView::OnMouseMove(UINT nFlags, CPoint point)<br />

{<br />

CClientDC dc(this);<br />

CPen pen;<br />

CPen *ptrPenOld;<br />

int nMode;<br />

int i;<br />

}<br />

pen.CreatePen(PS_DOT, 1, RGB(0, 0, 0));<br />

ptrPenOld=dc.SelectObject(&pen);<br />

nMode=dc.SetROP2(R2_XORPEN);<br />

if(m_bNeedErase == TRUE)<br />

{<br />

dc.PolyBezier(m_ptCurve, 4);<br />

m_ptCurve[m_nCurrentPt]=point;<br />

for(i=m_nCurrentPt+1; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!