繪圖基礎--多邊形1
// polygon1.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,350,300));
}
// The message map
BEGIN_MESSAGE_MAP( CWindow, CFrameWnd )
ON_WM_PAINT()
END_MESSAGE_MAP()
// Handle exposures
void CWindow::OnPaint()
{
CPaintDC dc(this);
// Change the pen and brush
CPen pen(PS_SOLID, 2, RGB(0,0,255)), *oldPen;
CBrush brush(RGB(255,0,0)), *oldBrush;
oldPen = dc.SelectObject(&pen);
oldBrush = dc.SelectObject(&brush);
// Create an array of points for the polygon
CPoint a[10];
a[0] = CPoint(100,100);
a[1] = CPoint(150,100);
a[2] = CPoint(180,30);
a[3] = CPoint(210,100);
a[4] = CPoint(250,100);
a[5] = CPoint(220,130);
a[6] = CPoint(260,180);
a[7] = CPoint(180,150);
a[8] = CPoint(110,180);
a[9] = CPoint(140,130);
dc.Polygon(a, 10);
// return old pen and brush
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;
}