www.pudn.com > subject_1_113294.rar > Rectangle.cpp, change:2002-05-23,size:1747b


// Rectangle.cpp: implementation of the CRectangle class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "Paint.h" 
#include "Rectangle.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CRectangle::CRectangle():CElement() 
{ 
	LeftTop=*(new CPoint(0,0)); 
	RightBottom=*(new CPoint(0,0)); 
} 
 
CRectangle::CRectangle(bool IsFilled,int FillMode,COLORREF FillColor):CElement() 
{ 
	this->IsFilled=IsFilled; 
	this->FillMode=FillMode; 
	this->FillColor=FillColor; 
 
	LeftTop=*(new CPoint(0,0)); 
	RightBottom=*(new CPoint(0,0)); 
} 
 
CRectangle::~CRectangle() 
{ 
} 
 
void CRectangle::DrawItem(CDC *pDC) 
{ 
	CPen *Pen=new CPen(); 
	CPen *OldPen; 
	Pen->CreatePen(LineStyle,LineWidth,LineColor); 
	OldPen=pDC->SelectObject(Pen); 
 
	CBrush *Brush=new CBrush(); 
	CBrush *OldBrush; 
	if(!IsFilled) 
	{		 
		Brush->CreateStockObject(NULL_BRUSH); 
		OldBrush=pDC->SelectObject(Brush);		 
	} 
	else if(FillMode==-1) 
	{ 
		Brush->CreateSolidBrush(FillColor); 
		OldBrush=pDC->SelectObject(Brush); 
	} 
	else 
	{ 
		Brush->CreateHatchBrush(FillMode,FillColor); 
		OldBrush=pDC->SelectObject(Brush); 
	} 
	pDC->Rectangle(LeftTop.x,LeftTop.y,RightBottom.x,RightBottom.y); 
 
	pDC->SelectObject(OldPen); 
	pDC->SelectObject(OldBrush); 
	delete Brush; 
	delete Pen; 
} 
 
void CRectangle::Serialize(CArchive &ar) 
{ 
	CElement::Serialize(ar); 
	if(ar.IsStoring()) 
	{ 
		ar<<LeftTop; 
		ar<<RightBottom; 
	} 
	else 
	{ 
		ar>>LeftTop; 
		ar>>RightBottom; 
	} 
}