MFC图形的使用:如何在网格中用鼠标绘图

如题所述

鼠标按下能获取到当前坐标,促发鼠标按下事件;

鼠标放开能获取到当前坐标,促发鼠标放开事件。
可以在这两个事件响应函数中进行绘图。追问

具体函数

追答

 

void CDrawLinesDlg::OnLButtonDown(UINT nFlags, CPoint point) 

{

 // TODO: Add your message handler code here and/or call default

 m_ptLastPoint = point;

 CDialog::OnLButtonDown(nFlags, point);

}

void CDrawLinesDlg::OnLButtonUp(UINT nFlags, CPoint point) 

{

 // TODO: Add your message handler code here and/or call default

 m_ptSecondPoint = point;

 CClientDC dc(this);

  if(m_nDrawType == 0) //画线

  {

   dc.MoveTo(m_ptLastPoint);

   dc.LineTo(point);

  }

  else if(m_nDrawType == 1)

  {

   dc.Rectangle(m_ptLastPoint.x,m_ptLastPoint.y,point.x,point.y);

  }

  else

  {

   dc.Ellipse(m_ptLastPoint.x,m_ptLastPoint.y,point.x,point.y);

  }

 CDialog::OnLButtonUp(nFlags, point);

}

void CDrawLinesDlg::OnMouseMove(UINT nFlags, CPoint point) 

{

 // TODO: Add your message handler code here and/or call default

 if((nFlags & MK_LBUTTON)==MK_LBUTTON)

 {

  //真正的实时绘画应该在这里做。

  //记得每次擦除上一次绘画的内容,画上这一次绘画的内容。

 }

 

 CDialog::OnMouseMove(nFlags, point);

}

 

 

 

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网