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


// AnyPolygonTool.cpp: implementation of the CAnyPolygonTool class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "AnyPolygonTool.h" 
#include "AnyPolygon.h" 
#include "Shape.h" 
#include "list.h" 
 
extern CList<CShape *> m_list; 
 
CAnyPolygonTool::CAnyPolygonTool(HWND hWnd): 
CTool(hWnd),m_line(hWnd,true),m_count(0) 
{ 
  
} 
 
CAnyPolygonTool::~CAnyPolygonTool() 
{ 
 
} 
 
void CAnyPolygonTool::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=curPoint;               //记录多边形起点 
			 m_status=FirstClick; 
		     			  
			 m_clickPT[m_count]=m_begPT;   //将坐标点存入数组 
             m_count++;               //点数加一 
		   } 
		break; 
	   case FirstClick: 
		   { 
             m_line.OnLButtonDown(wParam,lParam);    //结束划线 
             m_line.OnLButtonDown(wParam,lParam);    //开始划下条线 
             
              
			 m_clickPT[m_count]=curPoint;   //将坐标点存入数组 
             m_count++;               //点数加一 
		   } 
		 break; 
	   default: 
		   break; 
 
   } 
 
} 
 
void CAnyPolygonTool::OnMouseMove(WPARAM wParam,LPARAM lParam) 
{ 
   if(m_status==FirstClick) 
   { 
    m_line.OnMouseMove(wParam,lParam); 
   } 
 
} 
 
void CAnyPolygonTool::OnRButtonDown(WPARAM wParam,LPARAM lParam) 
{ 
    POINT curPoint; 
    curPoint.x=LOWORD(lParam); 
    curPoint.y=HIWORD(lParam); 
		 
	if(m_status==FirstClick) 
	{ 
	  m_status=NoClick; 
      m_line.OnLButtonDown(wParam,lParam);  //划线结束 
	  m_endPT=curPoint;                    //记录下结束点 
      
	  m_clickPT[m_count]=m_endPT; 
      m_count++; 
	  m_hdc=GetDC(m_hWnd); 
 
      penattrib->GetPen(m_hdc,false,false); 
	  this->Draw(); //图形封口 
      penattrib->ReleasePen(false,false); 
      this->SaveSelf(); 
	   
	  ReleaseDC(m_hWnd,m_hdc);  
      
       
	} 
      
} 
 
void CAnyPolygonTool::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 CAnyPolygonTool::SaveSelf() 
{ 
   CShape* pAnyPolygon=new CAnyPolygon(m_clickPT,m_count); 
 
   pAnyPolygon->SetLOGPEN(penattrib->GetPenStyle(false)); 
   pAnyPolygon->SetLOGBRUSH(penattrib->GetBrushStyle(false)); 
    
   m_list.AddTail(pAnyPolygon); 
   m_list.SetEditStatus(true); 
   m_count=0; 
	 
}