PolyPolygon, Polyline, Polygon的简单用法

本文介绍了使用C++在设备上下文中绘制多边形的方法。包括如何定义顶点坐标,使用Polygon函数绘制简单多边形,以及通过PolyPolygon函数绘制复合多边形。展示了通过不同函数实现复杂图形绘制的具体代码实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

BOOL Polygon(LPPOINT lpPoints, int nCount);

void CExoView::OnDraw(CDC* pDC)
{
	CPoint Pt[7];
	Pt[0] = CPoint(20, 50);
	Pt[1] = CPoint(180, 50);
	Pt[2] = CPoint(180, 20);
	Pt[3] = CPoint(230, 70);
	Pt[4] = CPoint(180, 120);
	Pt[5] = CPoint(180, 90);
	Pt[6] = CPoint(20, 90);

	pDC->Polygon(Pt, 7);
}



Drawing Polygons

void CView1View::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CPoint PtLine[] = { CPoint( 50,  50), CPoint(670,  50),
			  CPoint(670, 310), CPoint(490, 310),
			  CPoint(490, 390), CPoint(220, 390),
			  CPoint(220, 310), CPoint( 50, 310), 
			  CPoint( 50,  50) };

	CPoint Bedroom1[] = { CPoint( 55,  55), CPoint(175,  55),
			    CPoint(175, 145), CPoint( 55, 145)};
	CPoint Closets[]  = { CPoint( 55, 150), CPoint(145, 150),
			    CPoint(145, 205), CPoint( 55, 205) };
	CPoint Bedroom2[] = { CPoint(55, 210), CPoint(160, 210),
			    CPoint(160, 305), CPoint(55, 305) };

	dc.MoveTo(PtLine[0]);
	dc.LineTo(PtLine[1]);
	dc.LineTo(PtLine[2]);
	dc.LineTo(PtLine[3]);
	dc.LineTo(PtLine[4]);
	dc.LineTo(PtLine[5]);
	dc.LineTo(PtLine[6]);
	dc.LineTo(PtLine[7]);
	dc.LineTo(PtLine[8]);

	dc.Polygon(Bedroom1, 4);
	dc.Polygon(Closets, 4);
	dc.Polygon(Bedroom2, 4);
	// Do not call CView::OnPaint() for painting messages
}

BOOL PolyPolygon(LPPOINTlpPoints, LPINT lpPolyCounts, int nCount);

void CExoView::OnDraw(CDC* pDC)
{
	CPoint Pt[12];
	int lpPts[] = { 3, 3, 3, 3 };

	// Top Triangle
	Pt[0] = CPoint(125,  10);
	Pt[1] = CPoint( 95,  70);
	Pt[2] = CPoint(155,  70);

	// Left Triangle
	Pt[3] = CPoint( 80,  80);
	Pt[4] = CPoint( 20, 110);
	Pt[5] = CPoint( 80, 140);

	// Bottom Triangle
	Pt[6] = CPoint( 95, 155);
	Pt[7] = CPoint(125, 215);
	Pt[8] = CPoint(155, 155);
	
	// Right Triangle
	Pt[9] = CPoint(170,  80);
	Pt[10] = CPoint(170, 140);
	Pt[11] = CPoint(230, 110);

	pDC->PolyPolygon(Pt, lpPts, 4);
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hellokandy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值