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 感谢感谢

相关推荐
AA陈超1 小时前
虚幻引擎UE5专用服务器游戏开发-20 添加基础能力类与连招能力
c++·游戏·ue5·游戏引擎·虚幻
mit6.8242 小时前
[Meetily后端框架] AI摘要结构化 | `SummaryResponse`模型 | Pydantic库 | vs marshmallow库
c++·人工智能·后端
R-G-B2 小时前
【02】MFC入门到精通——MFC 手动添加创建新的对话框模板
c++·mfc·mfc 手动添加创建新的对话框
linux kernel2 小时前
第七讲:C++中的string类
开发语言·c++
Tipriest_2 小时前
[数据结构与算法] 优先队列 | 最小堆 C++
c++·优先队列·数据结构与算法·最小堆
宛西南浪漫戈命2 小时前
Centos 7下使用C++使用Rdkafka库实现生产者消费者
c++·centos·linq
帅_shuai_4 小时前
C++ 模板参数展开
c++
chilavert3184 小时前
技术演进中的开发沉思-30 MFC系列:五大机制
c++·windows
七七七七075 小时前
C++类对象多态底层原理及扩展问题
开发语言·c++
雨落倾城夏未凉5 小时前
8.Qt文件操作
c++·后端·qt