간단하게 CDC::Ellipse() 함수를 이용해서
윈도우에 랜덤한 타원을 출력시키는 프로그램.
CBrush와 CPen으로 브러시와 펜을 생성및 초기화 하고
SelectObject 함수로 DC에 선택한다.
#include <afxwin.h>
class CEllipseApp: public CWinApp
{
public:
virtual BOOL InitInstance();
};
CEllipseApp theApp;
class CMainWnd : public CFrameWnd
{
public:
CMainWnd();
~CMainWnd();
afx_msg void OnTimer(UINT nIDEvent);
DECLARE_MESSAGE_MAP();
};
void CMainWnd::OnTimer(UINT nIDEVENT)
{
CClientDC dc(this);
CRect rect;
GetClientRect(rect);
CBrush brush(RGB(rand()%255,rand()%255,rand()&255));
dc.SelectObject(&brush);
CPen pen(PS_SOLID,rand()%5,RGB(0,0,0));
dc.SelectObject(&pen);
dc.Ellipse(rand()%rect.Width(),rand()%rect.Height(),rand()%rect.Width(),rand()%rect.Height());
}
BEGIN_MESSAGE_MAP(CMainWnd,CFrameWnd)
ON_WM_TIMER()
END_MESSAGE_MAP()
BOOL CEllipseApp::InitInstance()
{
m_pMainWnd = new CMainWnd();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}
CMainWnd::CMainWnd()
{
Create(NULL,L"Ellipse");
SetTimer(10,100,NULL);
}
CMainWnd::~CMainWnd()
{
KillTimer(10);
}