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


// CurveTool.cpp: implementation of the CCurveTool class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "CurveTool.h" 
#include "Shape.h" 
#include "Curve.h" 
 
#include <stdio.h> 
 
extern CList<CShape *> m_list; 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CCurveTool::CCurveTool(HWND hWnd):CTool(hWnd),m_count(0) 
{ 
//	m_hdc=GetDC(m_hWnd); 
 
} 
 
CCurveTool::~CCurveTool() 
{ 
//	ReleaseDC(m_hWnd,m_hdc); 
 
} 
 
void CCurveTool::OnRButtonDown(WPARAM wParam, LPARAM lParam) 
{ 
	 
//	char temp[256]; 
//	sprintf(temp,"%d\n",m_list.GetCount()); 
//	MessageBox(m_hWnd,temp,"dsf",NULL); 
 
 
} 
 
void CCurveTool::OnMouseMove(WPARAM wParam, LPARAM lParam) 
{ 
	POINT curPoint; 
    curPoint.x=LOWORD(lParam); 
    curPoint.y=HIWORD(lParam); 
	switch(m_status) 
	{ 
	case NoClick: 
		m_count=0; 
		break; 
	case FirstClick: 
		{ 
		m_p[m_count]=curPoint;   //将坐标点存入数 
		m_count++; 
        if(m_count>499) 
		{ 
			m_count=499; 
 
			this->SaveSelf(); 
			m_count=0; 
//			m_status=NoClick; 
 
			 
		} 
		this->PreDraw(); 
		break; 
		} 
	default: 
		break; 
	} 
 
} 
 
void CCurveTool::OnLButtonDown(WPARAM wParam, LPARAM lParam) 
{ 
	POINT curPoint; 
	curPoint.x=LOWORD(lParam); 
	curPoint.y=HIWORD(lParam); 
	switch(m_status) 
	{ 
	   case NoClick: 
		   { 
			m_count=0; 
			m_status=FirstClick; 
            m_hdc=GetDC(m_hWnd); 
			penattrib->GetPen(m_hdc,false,false);		  
			m_p[m_count]=curPoint;   //将坐标点存入数组 
			m_count++;  
		   } 
		break; 
	   case FirstClick: 
		   { 
 
			m_p[m_count]=curPoint;   //将坐标点存入数组 
			m_count++;   //点数加一 
			 
			this->SaveSelf(); 
 
			m_status=NoClick; 
			 
			penattrib->ReleasePen(false,false); 
  //          m_count=0; 
			ReleaseDC(m_hWnd,m_hdc); 
		   } 
		 break; 
	   default: 
		   break; 
	} 
} 
 
void CCurveTool::SaveSelf() 
{ 
	CShape* newCure=new CCurve(m_p,m_count); 
 
   newCure->SetLOGPEN(penattrib->GetPenStyle(false)); 
   newCure->SetLOGBRUSH(penattrib->GetBrushStyle(false)); 
 
   m_list.AddTail(newCure); 
   m_list.SetEditStatus(true); 
 //  m_count=0; 
 
} 
 
void CCurveTool::PreDraw() 
{ 
	Polyline(m_hdc,m_p,m_count); 
}