如何从mouseOver删除以前绘制的形状?

时间:2019-02-13 16:34:35

标签: visual-c++ mfc

我正在尝试在视图上绘制一个矩形。当用户在移动鼠标的同时按住鼠标左键时,它应该显示形状,但是直到释放鼠标左键(诸如“绘画”之类的东西)时才绘制。

我当前的问题是,当我用鼠标左键向下移动鼠标时,它会在鼠标移动到的每个位置绘制一个矩形。因此最终在屏幕上显示出大量矩形。

我想知道当鼠标移到新位置时如何删除上一个,或者我的方法完全错误。

我在涂鸦项目中的经验有限。

void CMFCCalView::OnLButtonUp(UINT nFlags, CPoint point)
{
if (GetCapture() != this) {
    return;
}

CMFCCalDoc *pDoc = GetDocument();
CClientDC dc(this);

CPen *oldPen = dc.SelectObject(pDoc->getCurrentPen());
currShape->setEnding(point);
pDoc->m_shapeList.AddTail(currShape);
dc.SelectObject(oldPen);
ReleaseCapture();
return;
}


void CMFCCalView::OnLButtonDown(UINT nFlags, CPoint point)
{
CClientDC dc(this);
CMFCCalDoc *pDoc = GetDocument();
currShape = pDoc->newShape();
currShape->setBegining(point);
//  pDoc->debug.Format(_T("Shape : %d"),currShape->getShape());
SetCapture();
prePoint = point;
return;
}


void CMFCCalView::OnMouseMove(UINT nFlags, CPoint point)
{
if (GetCapture() != this) return;
CClientDC dc(this);
CPen *oldPen = dc.SelectObject(GetDocument()->getCurrentPen());
currShape->setEnding(point);
currShape->drawShape(&dc);
dc.SelectObject(oldPen);
prePoint = point;
return;
}

0 个答案:

没有答案
相关问题