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


// TriangleTool.cpp: implementation of the CTriangleTool class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "TriangleTool.h" 
#include "Triangle.h" 
#include "Shape.h" 
#include "list.h" 
 
extern CList<CShape *> m_list; 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CTriangleTool::CTriangleTool(HWND hWnd): 
CTool(hWnd),m_line(hWnd,true),m_operstatus(true) 
{ 
  
} 
 
CTriangleTool::~CTriangleTool() 
{ 
 
} 
 
void CTriangleTool::OnLButtonDown(WPARAM wParam,LPARAM lParam) 
{ 
   POINT curPoint; 
   curPoint.x=LOWORD(lParam); 
   curPoint.y=HIWORD(lParam); 
   
   switch(m_status) 
   { 
	   case NoClick: 
		   {  
             m_line.OnLButtonDown(wParam,lParam);  //开始划线 
             m_begPT=m_secondPT=m_endPT=m_oldPT=curPoint;               //记录多边形起点 
			 m_status=FirstClick; 
		   } 
		break; 
	   case FirstClick: 
		   { 			  
			 m_secondPT=m_endPT=m_oldPT=curPoint; 
             m_line.OnLButtonDown(wParam,lParam);    //结束划线 
             m_line.OnLButtonDown(wParam,lParam);    //开始划下条线 
             m_status=SecClick; 
              
		   } 
		 break; 
	   case SecClick: 
		   { 
			 
			m_line.OnLButtonDown(wParam,lParam);  //划线结束 
			m_endPT=m_oldPT=curPoint;                    //记录下结束点 
 
			penattrib->GetPen(m_hdc,false,false); 
			 
			this->Draw();  
			this->SaveSelf(); 
 
            penattrib->ReleasePen(false,false); 
			ReleaseDC(m_hWnd,m_hdc); 
			 
			m_status=NoClick; 
            m_operstatus=true; 
 
		   } 
		 break; 
   } 
} 
 
void CTriangleTool::OnMouseMove(WPARAM wParam,LPARAM lParam) 
{ 
   POINT curPoint; 
   curPoint.x=LOWORD(lParam); 
   curPoint.y=HIWORD(lParam); 
 
 
   if(m_status==FirstClick) 
   { 
 
    m_line.OnMouseMove(wParam,lParam);   
   } 
  if(m_status==SecClick) 
   { 
       m_line.OnMouseMove(wParam,lParam);  
 
	   m_hdc=GetDC(m_hWnd); 
	   m_endPT=curPoint; 
 
       penattrib->GetPen(m_hdc,true); 
	   if(m_operstatus) 
	   { 
		 m_operstatus=false;  
		 this->Draw(); 
		 m_oldPT=m_endPT; 
	   } 
	   else 
	   { 
         this->PreDraw(); 
	   } 
	    
        
   } 
} 
 
void CTriangleTool::OnRButtonDown(WPARAM wParam,LPARAM lParam) 
{ 
 
 
	 
} 
 
void CTriangleTool::Draw()           
{ 
	::MoveToEx(m_hdc,m_begPT.GetPoint().x,m_begPT.GetPoint().y,NULL);		 
	::LineTo(m_hdc,m_endPT.GetPoint().x,m_endPT.GetPoint().y);	 
} 
 
void CTriangleTool::SaveSelf() 
{ 
    CShape* PTriangle=new CTriangle(m_begPT,m_secondPT,m_endPT); 
   PTriangle->SetLOGPEN(penattrib->GetPenStyle(false)); 
   PTriangle->SetLOGBRUSH(penattrib->GetBrushStyle(false)); 
   m_list.AddTail(PTriangle); 
   m_list.SetEditStatus(true); 
} 
 
void CTriangleTool::PreDraw() 
{		 
	::MoveToEx(m_hdc,m_begPT.GetPoint().x,m_begPT.GetPoint().y,NULL);		//覆盖旧线 
	::LineTo(m_hdc,m_oldPT.GetPoint().x,m_oldPT.GetPoint().y); 
 
	::MoveToEx(m_hdc,m_begPT.GetPoint().x,m_begPT.GetPoint().y,NULL);		//绘制新线 
	::LineTo(m_hdc,m_endPT.GetPoint().x,m_endPT.GetPoint().y); 
	m_oldPT = m_endPT; 
 
}