mfc学习笔记2

对于上一次的问题,我已经自己搞定了解决方式。主要思想为采用异或笔,将原有轨迹擦除代码如下

void CLession4View::OnMouseMove(UINT nFlags, CPoint point) 
void Clesson4View::OnMouseMove(UINT nFlags, CPoint point)
{   
 // TODO: Add your message handler code here and/or call default   
 //画线   
//  CClientDC dc(this);   
//  if (m_bdraw)   
//  {   
//   dc.MoveTo(m_beginpoint);   
//   dc.LineTo(point);   
//   m_beginpoint=point;   
//  }   
	 if (m_bdraw)   
 {   
	//////RECT lpRect;   
	////// ::GetClientRect(m_hWnd, &lpRect);   
	// CClientDC dc(this);
	//// 
	// CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH));   
	// CBrush *PoldBrush=dc.SelectObject(pBrush);   
	// dc.SetROP2(R2_NOTXORPEN); 
	//// //int hight = lpRect.bottom - lpRect.top;     
	//// //int width = lpRect.right - lpRect.left;     
	////dc.Rectangle(0,0,width,hight);   
	////// dc.SetROP2(R2_NOTXORPEN);
	//// //CClientDC dc(this);
	// dc.Rectangle(CRect(m_beginpoint,m_movepoint));
	//// dc.SelectObject(PoldBrush);   
	////
	////
	//	m_movepoint=point;
	//	dc.SetROP2(R2_NOTXORPEN); 
	//	dc.Rectangle(CRect(m_beginpoint,m_movepoint));
	////	//dc.Rectangle(CRect(m_beginpoint,point));
	//	dc.SelectObject(PoldBrush);

	//
	//  橡皮筋技术实现1
	    CClientDC dc(this);
        int oldmode=dc.SetROP2(R2_NOTXORPEN);
		CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH));   
		CBrush *PoldBrush=dc.SelectObject(pBrush);   
		dc.Rectangle(CRect(m_beginpoint,m_movepoint));
        m_movepoint=point;
		dc.Rectangle(CRect(m_beginpoint,m_movepoint));
        dc.SelectObject(PoldBrush);
        dc.SetROP2(oldmode);
        ReleaseDC(&dc);

		 
 }   
  
  CView::OnMouseMove(nFlags, point);   
}  



//void Clesson4View::OnNcLButtonDown(UINT nHitTest, CPoint point)
//{
//	// TODO: 在此添加消息处理程序代码和/或调用默认值
//
//	CView::OnNcLButtonDown(nHitTest, point);
//}


void Clesson4View::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	m_beginpoint=point;
	m_bdraw=true;
	m_beginpoint = m_movepoint = point; 

	CView::OnLButtonDown(nFlags, point);
}

 但是又产生了一个新的问题。。就是两个重复的图形会全部不显示。。

是异或笔的原因,这该怎么办呢?

posted on 2012-09-10 15:17  wang-tsh  阅读(285)  评论(0编辑  收藏  举报

导航