如何在MFC中用鼠标画直线
答案:3 悬赏:40 手机版
解决时间 2021-04-07 04:57
- 提问者网友:佞臣
- 2021-04-06 13:57
如何在MFC中用鼠标画直线
最佳答案
- 五星知识达人网友:不甚了了
- 2021-04-06 15:33
OnLButtonDown(UINT nFlags, CPoint point)
{
::SetCursor(m_HCross);
m_Dragging=1;
m_PointOrigin=point;
m_PointOld=point;
SetCapture();
RECT Rect;
GetClientRect(&Rect);
ClientToScreen(&Rect);
::ClipCursor (&Rect);
CView::OnLButtonDown(nFlags, point);
}
OnMouseMove(UINT nFlags, CPoint point)
{
if(m_Dragging)
{
CClientDC dc(this);
dc.SetROP2 (R2_NOT);
dc.MoveTo (m_PointOrigin);
dc.LineTo (m_PointOld);
dc.MoveTo (m_PointOrigin);
dc.LineTo (point);
m_PointOld=point;
}
CView::OnMouseMove(nFlags, point);
}
OnLButtonUp(UINT nFlags, CPoint point)
{ CClientDC dc(this);
if(m_Dragging)
{
m_Dragging=0;
::ReleaseCapture ();
::ClipCursor (NULL);
dc.SetROP2 (R2_NOT);
dc.MoveTo (m_PointOrigin);
dc.LineTo (m_PointOld);
dc.MoveTo (m_PointOrigin);
dc.LineTo (point);
m_PointOld=point;
}
CView::OnLButtonUp(nFlags, point);
}
{
::SetCursor(m_HCross);
m_Dragging=1;
m_PointOrigin=point;
m_PointOld=point;
SetCapture();
RECT Rect;
GetClientRect(&Rect);
ClientToScreen(&Rect);
::ClipCursor (&Rect);
CView::OnLButtonDown(nFlags, point);
}
OnMouseMove(UINT nFlags, CPoint point)
{
if(m_Dragging)
{
CClientDC dc(this);
dc.SetROP2 (R2_NOT);
dc.MoveTo (m_PointOrigin);
dc.LineTo (m_PointOld);
dc.MoveTo (m_PointOrigin);
dc.LineTo (point);
m_PointOld=point;
}
CView::OnMouseMove(nFlags, point);
}
OnLButtonUp(UINT nFlags, CPoint point)
{ CClientDC dc(this);
if(m_Dragging)
{
m_Dragging=0;
::ReleaseCapture ();
::ClipCursor (NULL);
dc.SetROP2 (R2_NOT);
dc.MoveTo (m_PointOrigin);
dc.LineTo (m_PointOld);
dc.MoveTo (m_PointOrigin);
dc.LineTo (point);
m_PointOld=point;
}
CView::OnLButtonUp(nFlags, point);
}
全部回答
- 1楼网友:三千妖杀
- 2021-04-06 18:20
用鼠标划线,用Device context ,即设备上下文,用来在画布上划线和作图的。里面有很多工具,自己去查资料吧。用moveto(x,y)和Lineto(x,y);函数就可以了。
用鼠标控制也可以实现,也就是在mousemove中加点代码,让线随着鼠标做运动。动脑子好好想想吧,代码就不贴了。好久没用过VC了,呵呵
用鼠标控制也可以实现,也就是在mousemove中加点代码,让线随着鼠标做运动。动脑子好好想想吧,代码就不贴了。好久没用过VC了,呵呵
- 2楼网友:爱难随人意
- 2021-04-06 16:44
首先通过鼠标左键按下和鼠标左键弹起消息捕捉要画线的两个点,并存在CPoint类的对象中;然后在OnPaint()函数中用MoveTo(左键按下的点)和LineTo(左键弹起的点),这样就可以画线了,当然你可以用CPen类对象修改线条的颜色、样式和粗细
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯