// gameFrame.cpp : implementation file
//
#include "stdafx.h"
#include "gameFrame.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// gameFrame
IMPLEMENT_DYNCREATE(gameFrame, CFrameWnd)
CBrush brush[21];
CPen newPen,*oldPen;
gameFrame::gameFrame()
{
RECT rect;
Create(NULL,"绘图窗口");
CClientDC dc(this);
int width = dc.GetDeviceCaps(HORZRES);
int height = dc.GetDeviceCaps(VERTRES);
GetWindowRect( &rect );
width = ( width - ( rect.right - rect.left ))/2 ;
height = (height - (rect.bottom - rect.top ))/2 ;
MoveWindow( width ,
height ,
(rect.right - rect.left ) ,
(rect.bottom - rect.top ) ,
true );
COLORREF color[3] = { RGB(255,0,0),RGB(0,255,0),RGB(0,0,255) };
int style[6] = { HS_VERTICAL, HS_HORIZONTAL,
HS_CROSS, HS_DIAGCROSS,
HS_FDIAGONAL, HS_BDIAGONAL };
newPen.CreatePen(PS_DASH,5,RGB(50,50,50));
for(int arrayIdx=0,colorIdx=0; colorIdx<3; colorIdx++) {
brush[arrayIdx++].CreateSolidBrush(color[colorIdx]);
}
for(int styleIdx=0; styleIdx<6; styleIdx++) {
for(colorIdx=0; colorIdx<3; colorIdx++) {
brush[arrayIdx++].CreateHatchBrush(style[styleIdx],color[colorIdx]);
}
}
}
gameFrame::~gameFrame()
{
}
BEGIN_MESSAGE_MAP(gameFrame, CFrameWnd)
//{{AFX_MSG_MAP(gameFrame)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// gameFrame message handlers
void gameFrame::OnPaint()
{
int x1=10, y1=10, x2=70, y2=70;
CPaintDC dc(this);
oldPen = dc.SelectObject(&newPen);
for(int arrayIdx=0;arrayIdx<21;arrayIdx++)
{
dc.SelectObject(&brush[arrayIdx]);
dc.Ellipse(x1,y1,x2,y2);
if((arrayIdx+1)%3 == 0)
{
x1+=80;
x2+=80;
y1=10;
y2=70;
}
else
{
y1+=100;
y2+=100;
}
}
dc.SelectObject(oldPen);
}
评论0