画直线的问题,实现橡皮筋效果出现问题
通过鼠标控制,点第一下定起点,再点第二下定终点画一条直线,但是实现起来画出来的效果是move到哪里直线就出现到哪里,不知道SetROP2(R2_NOTXORPEN)该加到哪里合适
源代码如下
void CMyLine2View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_nStep==1)
{
CDrawLine line1(m_OrgPnt,m_PrePnt);
line1.Draw();
CDrawLine line2(m_OrgPnt,point);
line2.Draw();
}
CView::OnMouseMove(nFlags, point);
}
void CMyLine2View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_nStep++; // 记录鼠标点击次数 初始值为0
if (m_nStep==1)
{
m_OrgPnt=point;
m_PrePnt=point;
}
else
{
CDrawLine* pLine=new CDrawLine(m_OrgPnt,point);
pLine->Draw();
pLine->Draw();
m_nStep=0;
}
CView::OnLButtonDown(nFlags, point);
}
//画线函数
void CDrawLine::Draw()
{
ASSERT_VALID(g_pView);
CDC* pDC=g_pView->GetDC();
pDC->MoveTo(m_StartPnt);
pDC->LineTo(m_EndPnt);
}