⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 shape.cpp

📁 《MFC经典问答》pdf格式 拿出来大家共享一下
💻 CPP
字号:
#include "stdafx.h"
#include "CustomPrintingDialog.h"

#include "Shape.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CShape

IMPLEMENT_SERIAL(CShape, CObject, 1)

CShape::CShape( CPoint ptCenter, COLORREF crColor, SHAPE shape )
{
	m_ptCenter = ptCenter;
	m_crColor = crColor;
	m_shape = shape;
}


CShape::CShape()
{
	m_ptCenter = CPoint( 0, 0 );
	m_crColor = 0;
	m_shape = SQUARE;
}


void CShape::Draw( CDC* pDC ) const
{
	DrawAt( pDC, m_ptCenter.x, m_ptCenter.y );
}


void CShape::DrawAt( CDC* pDC, int x, int y ) const
{
	ASSERT_VALID( pDC );

	CBrush brFill( m_crColor );
	CBrush* pOldBrush = pDC->SelectObject( &brFill );

	CRect rect( x-HALF_SIZE, y-HALF_SIZE, x+HALF_SIZE, y+HALF_SIZE );

	switch( m_shape )
	{
	default:
		ASSERT( FALSE );	// unknown shape type
		break;

	case SQUARE:
		pDC->Rectangle( rect );
		break;

	case CIRCLE:
		pDC->Ellipse( rect );
		break;
	}

	CPen pen( PS_SOLID, 6, RGB( 0, 0, 0 ) );
	CPen* pOldPen = pDC->SelectObject( &pen );

	pDC->MoveTo( x-10, y-10 );
	pDC->LineTo( x+10, y+10 );

	pDC->MoveTo( x-10, y+10 );
	pDC->LineTo( x+10, y-10 );

	pDC->SelectObject( pOldPen );
	pDC->SelectObject( pOldBrush );
}


void CShape::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		ar << m_ptCenter << (DWORD) m_crColor << (DWORD) m_shape;
	}
	else
	{
		ar >> m_ptCenter >> (DWORD&) m_crColor >> (DWORD&) m_shape;
	}
}


CString CShape::GetShapeName() const
{
	CString strShape;
	switch( m_shape )
	{
	default:
		ASSERT( FALSE );	// unknown shape type
		break;

	case SQUARE:
		strShape = _T( "Square" );
		break;

	case CIRCLE:
		strShape = _T( "Circle" );
		break;
	}

	return strShape;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -