目标,鼠标按下,开始划线,鼠标抬起,划线结束,再次划线的时候可以进行擦除。
void CTest1View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
Cstartpoint=point;
b_Draw=true;
CView::OnLButtonDown(nFlags, point);
}
void CTest1View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(isDrawLine)
{
if(Cstartpoint.x==0)
{//如果是第一次绘图,则绘图,并给Cstartpoint赋值
dc.MoveTo(radius,radius);
dc.LineTo(point);
Cstartpoint.x=point.x;Cstartpoint.y=point.y;
}
//如果不是第一次绘图,则先擦除上次绘制的线
dc.SetROP2(R2_NOT);
dc.MoveTo(radius,radius);
dc.LineTo(Cstartpoint);
Cstartpoint.x=point.x;Cstartpoint.y=point.y;
//绘制本次的线
dc.MoveTo(radius,radius);
dc.LineTo(point);
}
CView::OnMouseMove(nFlags, point);
}
void CTest1View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
b_Draw=false;
//擦除最后留下的那根线
CTest1View dc(this);
dc.SetROP2(R2_NOT);
dc.MoveTo(radius,radius);
dc.LineTo(Cstartpoint);
CView::OnLButtonUp(nFlags, point);
}