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

来源:互联网 发布:上海瀚威酩轩 知乎 编辑:程序博客网 时间:2024/06/03 14:36

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 0
原创粉丝点击