繪圖基礎--橢圓

繪圖基礎--橢圓


// ellipse.cpp

#include <afxwin.h>

// Define the application class
class CApp : public CWinApp
{
public:
	virtual BOOL InitInstance();
};

CApp App;  

// define the window class
class CWindow : public CFrameWnd
{ 
public:
	CWindow(); 
	void OnPaint();
	DECLARE_MESSAGE_MAP()
};

// The window's constructor
CWindow::CWindow()
{ 
	Create(NULL, "Drawing Tests",WS_OVERLAPPEDWINDOW,CRect(0,0,500,400)); 
}

// The message map
BEGIN_MESSAGE_MAP( CWindow, CFrameWnd )
	ON_WM_PAINT()	
END_MESSAGE_MAP()

// Handle exposures
void CWindow::OnPaint()
{
	CRect rect;

	GetClientRect( rect );
	CPaintDC dc(this);
	
	// Create a new pen
	CPen pen(PS_SOLID, 2, RGB(0,0,255)), *oldPen;
	oldPen = dc.SelectObject(&pen);
	
	// Create a new brush
	CBrush brush(HS_CROSS,RGB(255,0,0)), *oldBrush;
	oldBrush = dc.SelectObject(&brush);
	
	// Draw a rectangle with the new pen and brush
	rect.InflateRect(-20, -20);		
	dc.Ellipse(rect);

	dc.SelectObject(oldPen);
	dc.SelectObject(oldBrush);
}

// Init the application
BOOL CApp::InitInstance()
{
	m_pMainWnd = new CWindow();
	m_pMainWnd->ShowWindow(m_nCmdShow);
	m_pMainWnd->UpdateWindow();
	return TRUE;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章