www.pudn.com > my2cadtest07261930.rar > Tool.cpp, change:2006-07-25,size:1657b


#include "stdafx.h" 
#include "Tool.h" 
 
CTool::CTool(HWND hWnd):m_hWnd(hWnd),m_status(NoClick) 
{ 
 
} 
 
CTool::~CTool() 
{ 
 
} 
 
void CTool::OnLButtonDown(WPARAM wParam, LPARAM lParam) 
{ 
	POINT curPoint; 
	curPoint.x=LOWORD(lParam); 
    curPoint.y=HIWORD(lParam); 
	switch (m_status) 
	{ 
	   case NoClick : 
		 m_begPT=m_oldPT=m_endPT=curPoint; 
	     m_status=FirstClick; 
   
         m_hdc=GetDC(m_hWnd);        //打开绘图HDC准备绘图         
		 penattrib->GetPen(m_hdc,true);  //选异或笔 
 
        break; 
	    case FirstClick : 
			 m_endPT=curPoint; 
		     m_status=NoClick; 
             penattrib->ReleasePen(true); 
		     penattrib->GetPen(m_hdc,false,false);  //换最终笔	  
			 this->Draw();       //再绘一次 
             penattrib->ReleasePen(false,false); 
			 this->SaveSelf();  //图形划好后 将构成图形的相关信息存入图形对象中,生成该图形对象 
		     
		  ReleaseDC(m_hWnd,m_hdc);  //图形绘制完成后关闭HDC 
		   
//		  SendMessage(m_hWnd, WM_COMMAND, IDM_OPER_CATCH,0); 
		 break;  
	}	 
} 
 
void CTool::OnMouseMove(WPARAM wParam, LPARAM lParam) 
{ 
    POINT curPoint; 
	curPoint.x=LOWORD(lParam); 
    curPoint.y=HIWORD(lParam); 
	if(m_status==FirstClick) 
	{ 
  	  m_endPT=curPoint; 
      this->PreDraw();      //派生类重写PreDraw方法       
	} 
 
} 
 
 
void CTool::OnRButtonDown(WPARAM wParam, LPARAM lParam) 
{ 
   
   
	  m_hdc=GetDC(m_hWnd);  
	  this->RollBackOper(m_hdc); 
	  ReleaseDC(m_hWnd,m_hdc); 
 
    
} 
 
 
void CTool::RollBackOper(HDC &hdc) 
{ 
  if(m_status!=NoClick) 
  { 
	  penattrib->GetPen(hdc,true); 
	  this->Draw(); 
      m_status=NoClick; 
	  penattrib->ReleasePen(true); 
  } 
   
}