在MFC下绘制直线,使用橡皮筋技术,可以使直线效果跟随鼠标移
void CGraphic1View::OnMouseMove(UINT nFlags, CPoint point) { if(MK_LBUTTON == nFlags) { CClientDC dc(this); int oldmode=dc.SetROP2(R2_NOTXORPEN); CPen pen(m_nLineStyle, m_nLineWidth, m_clr), *oldpen; oldpen = dc.SelectObject(&pen); dc.MoveTo(m_ptOrigin); dc.LineTo(m_ptEnd); m_ptEnd=point; dc.MoveTo(m_ptOrigin); dc.LineTo(m_ptEnd); dc.SelectObject(oldpen); dc.SetROP2(oldmode); ReleaseDC(&dc); } CScrollView::OnMouseMove(nFlags, point); } |
其中