问题描述:像WINDOWS“画图”工具一样,在利用鼠标画一条直线时,按住鼠标左键并拖拽,先画出随鼠标移动的直线,当释放左键后才真正画出一条所需的直线。
我的部分代码:
void CMy5_33View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCapture();
::SetCursor(m_hCross);
m_ptOrigin=point;
m_bDragging=TRUE;
CView::OnLButtonDown(nFlags, point);
}void CMy5_33View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDragging)
{
CClientDC dc(this);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
}
CView::OnMouseMove(nFlags, point);
}void CMy5_33View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDragging)
{
m_bDragging=false;
ReleaseCapture();
}
CView::OnLButtonUp(nFlags, point);
}
我的结果:
见附件
我的部分代码:
void CMy5_33View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
SetCapture();
::SetCursor(m_hCross);
m_ptOrigin=point;
m_bDragging=TRUE;
CView::OnLButtonDown(nFlags, point);
}void CMy5_33View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDragging)
{
CClientDC dc(this);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
}
CView::OnMouseMove(nFlags, point);
}void CMy5_33View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bDragging)
{
m_bDragging=false;
ReleaseCapture();
}
CView::OnLButtonUp(nFlags, point);
}
我的结果:
见附件
//加上擦除代码,擦出之前画出的
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
//加上擦除代码,擦出之前画出的
InvalidateRect(null);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);