【MFC】画线

1、DrawTestDlg.h

    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);

    CPoint m_originPoint;

2、DrawTestDlg.cpp

void CDrawTestDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
    m_originPoint.x = point.x;
    m_originPoint.y = point.y;

    CDialogEx::OnLButtonDown(nFlags, point);
}

void CDrawTestDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
    //首先获得窗口的设备描述表
    HDC hdc;
    hdc = ::GetDC(m_hWnd);
    //移动到线条的起点
    MoveToEx(hdc, m_originPoint.x, m_originPoint.y, NULL);
    //画线
    LineTo(hdc, point.x, point.y);
    //释放设备描述表
    ::ReleaseDC(m_hWnd, hdc);

    CDialogEx::OnLButtonUp(nFlags, point);
}

 

posted @ 2018-03-13 10:49  ~小小鸟~  阅读(590)  评论(0编辑  收藏  举报