MFC结合GDI+

MFC结合GDI+

创建一个空的MFC界面,在确定按钮函数里进行画图:

1、包含头文件与库

在stdafx.h中加入以下三行代码:

cpp 复制代码
#include "gdiplus.h"
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")

2、安装GDI+

在使用GDI+之前要进行安装,否则程序不会报错,但绘图不成功。安装方法如下:

cpp 复制代码
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR           gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

安装完成后就可以使用GDI+进行绘图了......

3、卸载GDI+

卸载调用如下函数即可

cpp 复制代码
GdiplusShutdown(gdiplusToken);

在确定按钮触发函数里添加如下画图函数:

cpp 复制代码
Graphics graphics(this->GetDC()->m_hDC);
	Pen greenPen(Color::Green, 3);
	PointF point1(100.0f, 100.0f);//开始点
	PointF point2(200.0f, 50.0f);
	PointF point3(400.0f, 10.0f);
	PointF point4(500.0f, 100.0f);
	PointF point5(600.0f, 200.0f);
	PointF point6(700.0f, 400.0f);
	PointF point7(500.0f, 500.0f);//结束点

	PointF curvePoints[7] = {
		point1,
		point2,
		point3,
		point4,
		point5,
		point6,
		point7 };
	PointF* pcurvePoints = curvePoints;
	//画闭合曲线
	graphics.DrawClosedCurve(&greenPen, curvePoints, 7);
	//画连接点
	SolidBrush redBrush(Color::Red);
	SolidBrush startBrush(Color::Blue);
	SolidBrush endBrush(Color::Black);
	graphics.FillEllipse(&startBrush, Rect(95, 95, 10, 10));
	graphics.FillEllipse(&redBrush, Rect(495, 95, 10, 10));
	graphics.FillEllipse(&redBrush, Rect(195, 45, 10, 10));
	graphics.FillEllipse(&redBrush, Rect(395, 5, 10, 10));
	graphics.FillEllipse(&redBrush, Rect(595, 195, 10, 10));
	graphics.FillEllipse(&redBrush, Rect(695, 395, 10, 10));
	graphics.FillEllipse(&endBrush, Rect(495, 495, 10, 10));

结果如下:

参考:https://www.cnblogs.com/chuncn/archive/2010/12/17/1908740.html 感谢感谢

相关推荐
派阿喵搞电子41 分钟前
在UI界面内修改了对象名,在#include “ui_mainwindow.h“没更新
c++·qt·ubuntu·ui
C++ 老炮儿的技术栈2 小时前
UDP 与 TCP 的区别是什么?
开发语言·c++·windows·算法·visual studio
mochensage3 小时前
CSP信奥赛C++常用系统函数汇总
c++·信奥
mochensage3 小时前
C++信息学竞赛中常用函数的一般用法
java·c++·算法
fpcc3 小时前
跟我学c++中级篇——多线程中的文件处理
c++
5:004 小时前
云备份项目
linux·开发语言·c++
乄夜5 小时前
嵌入式面试高频(5)!!!C++语言(嵌入式八股文,嵌入式面经)
c语言·c++·单片机·嵌入式硬件·物联网·面试·职场和发展
YYDS3145 小时前
C++动态规划-01背包
开发语言·c++·动态规划
wydaicls6 小时前
十一.C++ 类 -- 面向对象思想
开发语言·c++
姜君竹6 小时前
QT的工程文件.pro文件
开发语言·c++·qt·系统架构