• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
james1207

博客园    首页    新随笔    联系   管理    订阅  订阅

绘图基础--多边形2

绘图基础--多边形2


 

// polygon2.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 exposure
void CWindow::OnPaint()
{
	CPaintDC dc(this);
	
	// Change the pen and the 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 the polygon
	CPoint a[10];
	a[0] = CPoint(100,100);	
	a[1] = CPoint(250,100);
	a[2] = CPoint(110,180); 
	a[3] = CPoint(180,30);
	a[4] = CPoint(260,180);    

	dc.SetPolyFillMode(ALTERNATE);
	dc.Polygon(a, 5);
	
	// 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;
}


 

 

posted @ 2013-09-18 20:07  Class Xman  阅读(203)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3