画直线(橡皮筋)

  在《深入浅出MFC》中的step2的程序的基础上进行修改,原程序是连续画线,进行修改使它画直线

void CScribbleView::OnLButtonDown(UINT, CPoint point) 

{

    // Pressing the mouse button in the view window starts a new stroke

 

m_pStrokeCur = GetDocument()->NewStroke();

// Add first point to the new stroke

m_pStrokeCur->m_pointArray.Add(point);

 

SetCapture();       // Capture the mouse until button up.

m_ptPrev = point;   // Serves as the MoveTo() anchor point for the

// LineTo() the next point, as the user drags the

// mouse.

m_ptNext = m_ptPrev;

 

m_button = TRUE;

return;

}

 

void CScribbleView::OnLButtonUp(UINT, CPoint point) 

{

// Mouse button up is interesting in the Scribble application

// only if the user is currently drawing a new stroke by dragging

// the captured mouse.

 

if (GetCapture() != this)

return; // If this window (view) didn't capture the mouse,

// then the user isn't drawing in this window.

 

CScribbleDoc* pDoc = GetDocument();

 

CClientDC dc(this);

 

CPen* pOldPen = dc.SelectObject(pDoc->GetCurrentPen());

dc.MoveTo(m_ptPrev);

dc.LineTo(point);

dc.SelectObject(pOldPen);

m_pStrokeCur->m_pointArray.Add(point);

 

ReleaseCapture();   // Release the mouse capture established at

// the beginning of the mouse drag.

m_button =FALSE;

return;

}

 

void CScribbleView::OnMouseMove(UINT, CPoint point) 

{

// Mouse movement is interesting in the Scribble application

// only if the user is currently drawing a new stroke by dragging

// the captured mouse.

//

if(m_button)

{

CClientDC   dc(this);       

dc.SetROP2(R2_NOT); 

//该函数的主要的作用是根据nDrawMode设置的方式重新设定绘图的方式,下面就不同的nDrawMode值具体解释绘图模式是如何改变的

dc.MoveTo(m_ptPrev);    

dc.LineTo(m_ptNext);     

m_ptNext = point;     

dc.MoveTo(m_ptPrev);    

dc.LineTo(m_ptNext);    

}

return;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值