MFC鼠标移动画线并获取坐标
想实现按住鼠标左键实时画线 也就是一直点着鼠标左键画线,并可以获取点的坐标,可是如下代码只能实现点一下画一条直线,应当如何修改?求问大神
void CGisDemoView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
SetCapture();
if(m_toolflag == 0) //画点
{
CGisPoint *p_Point = new CGisPoint(point.x,point.y,false,0);
m_pPointArray.Add(p_Point);
dc.SetPixel(point,RGB(0,0,0));
}
else if(m_toolflag == 1 || m_toolflag ==2) //画线,多边形
{
m_bRBtnDown = false;
m_nPushNUm++;
if(m_nPushNUm == 1) //若第一次按下则只记录坐标
{
m_fistPoint = point;
m_OldPoint = point;
m_OrignPoint = point;
m_xPoint[0] = point.x;
m_yPoint[0] = point.y;
}
else if(m_nPushNUm > 1) //以后按下记录坐标并画线
{
m_xPoint[m_nPushNUm-1] = point.x;
m_yPoint[m_nPushNUm-1] = point.y;
dc.MoveTo(m_OldPoint);
dc.LineTo(point);
m_OldPoint = point;
m_OrignPoint = point;
}
}
ReleaseCapture();
CView::OnLButtonDown(nFlags, point);
}
void CGisDemoView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
dc.SetROP2(R2_NOT);
if((m_toolflag ==1 || m_toolflag ==2) && m_nPushNUm > 0)
{
if(m_OrignPoint != point) //或新点与旧点不同,则除去旧线,画新线并存新点
{
dc.MoveTo(m_OldPoint);
dc.LineTo(m_OrignPoint);
dc.MoveTo(m_OldPoint);
dc.LineTo(point);
m_OrignPoint = point;
}
}
CView::OnMouseMove(nFlags, point);
}
void CGisDemoView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
dc.SetROP2(R2_NOT);
if(m_toolflag == 2 && !m_bRBtnDown)
{
m_bRBtnDown = true;
int *x = new int[m_nPushNUm];
int *y = new int[m_nPushNUm];
for(int i=0; i< m_nPushNUm;i++)
{
x[i] = m_xPoint[i];
y[i] = m_yPoint[i];
}
//创建当前面对象
CGisPolygon *pPolygon = new CGisPolygon(x,y,false,0,m_nPushNUm);
m_pPolygonArray.Add(pPolygon);
//除去旧线
dc.MoveTo(m_OldPoint);
dc.LineTo(m_OrignPoint);
//画新线
dc.MoveTo(m_OldPoint);
dc.LineTo(m_fistPoint);
m_nPushNUm = 0;
}
CView::OnRButtonDown(nFlags, point);
}
void CGisDemoView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
dc.SetROP2(R2_NOT);
if(m_toolflag == 1 && !m_bRBtnDown)
{
m_bRBtnDown = true;
int *x = new int[m_nPushNUm];
int *y = new int[m_nPushNUm];
for(int i=0; i< m_nPushNUm;i++)
{
x[i] = m_xPoint[i];
y[i] = m_yPoint[i];
}
//生成线对象并存储
CGisPLine *pPline = new CGisPLine(x,y,false,0,m_nPushNUm);
m_pLineArray.Add(pPline);
//除去旧线,画新线
dc.MoveTo(m_OldPoint);
dc.LineTo(m_OrignPoint);
dc.MoveTo(m_OldPoint);
dc.LineTo(point);
m_nPushNUm = 0;
}
CView::OnLButtonDblClk(nFlags, point);
}