工控编程吧
标题: 上位机MFCV如何绘制图形 [打印本页]
作者: qq263946146 时间: 2019-7-31 10:27
标题: 上位机MFCV如何绘制图形
CPaintDC或CDC等都带有非常丰富的图形绘制函数,
比如绘制直线LineTo,
绘制矩形Rectangle。
绘制椭圆Ellipse
当前我们准备一个例程供大家参考。
例程运行后会启动一个定时 器,不间断刷新界面,绘制不同图形
- CRect rect;
- GetClientRect(rect);
- rect.InflateRect(-50, -50, -50, -50);
- CPaintDC dc(this);
- //绘制直线
- if (m_nDraw == 1)
- {
- dc.MoveTo(rect.left, rect.top);
- dc.LineTo(rect.right, rect.bottom);
- }
- //绘制矩形
- else if (m_nDraw == 2)
- {
- dc.Rectangle(rect);
- }
- //绘制圆形或椭圆形
- else if (m_nDraw == 3)
- {
- dc.Ellipse(rect);
- }
- //绘制扇形
- else if (m_nDraw == 4)
- {
- dc.Pie(rect,
- CPoint(rect.right, rect.CenterPoint().y),
- CPoint(rect.CenterPoint().x, rect.right));
- }
- //绘制多边形
- else if (m_nDraw == 5)
- {
- CPoint point[4];
- point[0].x = rect.left + rect.Width() / 2;
- point[0].y = rect.top;
- point[1].x = rect.right;
- point[1].y = rect.top + rect.Height() / 2;
- point[2].x = point[0].x;
- point[2].y = rect.bottom;
- point[3].x = rect.left;
- point[3].y = point[1].y;
- dc.Polygon(point, 4);
- }
- else if (m_nDraw == 6)
- {
- dc.RoundRect(rect, CPoint(50, 50));
- }
复制代码
(, 下载次数: 0)