?? shape.cpp
字號:
#include "stdafx.h"
#include "DynamicPagination.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 + -