lesson4_MFC实现单文档应用程序画线

1>在CDrawView类中增加2个消息响应函数void CDrawView::OnLButtonDown(UINT nFlags, CPoint point) 与void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
再增加1个成员对象用来保存点CPoint m_ptOrigin;

/////////////////////////////////////////////////////////////////////////////
// CDrawView message handlers
//鼠标按下时调用如下方法
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point) 
{
    // TODO: Add your message handler code here and/or call default
    //MessageBox("view clicked");
    m_ptOrigin = point;
    CView::OnLButtonDown(nFlags, point);
}

//弹起时调用如下方法
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) 
{
    // TODO: Add your message handler code here and/or call default
    HDC hdc;
    hdc = ::GetDC(m_hWnd);
    MoveToEx(hdc,m_ptOrigin.x,m_ptOrigin.y,NULL);
    LineTo(hdc,point.x,point.y);
    ::ReleaseDC(m_hWnd,hdc);

    CView::OnLButtonUp(nFlags, point);
}

2>按下的方法不变,在弹起的方法中重新实现也可实现划线
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) 
{
    // TODO: Add your message handler code here and/or call default
    CDC *pDC = GetDC();
    pDC->MoveTo(m_ptOrigin);
    pDC->LineTo(point);
    ReleaseDC(pDC);
    CView::OnLButtonUp(nFlags,point);
}

3>按下的方法不变,在弹起的方法中重新实现也可实现划线
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) 
{
    // TODO: Add your message handler code here and/or call default
    CClientDC dc(this);
    CClientDC dc(GetParent());
    dc.MoveTo(m_ptOrigin);
    dc.LineTo(point);
}

4>按下的方法不变,在弹起的方法中重新实现也可实现划线
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point) 
{
    // TODO: Add your message handler code here and/or call default
    //CWindowDC dc(this);
    CWindowDC dc(GetParent());
    dc.MoveTo(m_ptOrigin);
    dc.LineTo(point);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值