-
Problem in Paint
Following is the code for the ON_WM_MOUSEMOVE in my paint program.
Code:
void CPainterView::OnMouseMove(UINT nFlags, CPoint point)
{
CClientDC *pDC = new CClientDC (this);
switch (flag)
{
case 1:
//drawing freehand
break;
case 2:
//drawing line
if (nFlags && MK_LBUTTON)
{
pDC->SelectStockObject(WHITE_PEN);
pDC->MoveTo (Anchor.x,Anchor.y);
pDC->LineTo (OldPoint.x, OldPoint.y);
pDC->SelectStockObject (BLACK_PEN);
pDC->MoveTo (Anchor.x, Anchor.y);
pDC->LineTo (point.x, point.y);
}
break;
case 3:
//drawing a rectangle
if (nFlags && MK_LBUTTON )
{
pDC->SelectStockObject (WHITE_PEN);
pDC->SelectStockObject(NULL_BRUSH);
pDC->Rectangle(Anchor.x,Anchor.y,OldPoint.x,OldPoint.y);
pDC->SelectStockObject(BLACK_PEN);
pDC->SelectStockObject(NULL_BRUSH);
pDC->Rectangle(Anchor.x,Anchor.y,point.x,point.y);
break;
}
}
OldPoint.x = point.x;
OldPoint.y = point.y;
}
OldPoint is already initialised to Anchor which is the Starting point, where the user clicked originally.
The Problem is when I try to draw a new rectangle on an older one, some part of the older one gets erased. Why is this happening?
And what do I do to Stop it.
Thankx.