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

相关推荐
chenbingjie_c6 小时前
C++ 进阶核心知识点总结:模板、内存分区、new/delete、内存池
开发语言·c++
Frank_refuel8 小时前
【C++】Json库介绍和使用
c++
重生之小比特8 小时前
【C++进阶】map和set
java·开发语言·c++
知识分享小能手9 小时前
C++ 学习教程,从入门到精通,C++对象和类 — 详细知识点总结(10)
开发语言·c++·学习
顺顺 尼9 小时前
linux 进程信号(上)
linux·c++·算法
海上小飞龙10 小时前
改一个数,右边全得重算,这题怎么扛住两万次查询
java·c++·python
Persistent的粽子!10 小时前
双指针算法:最大盛水容器
c++·算法·leetcode
小小龙学IT10 小时前
三菱 PLC MC 协议(SLMP / QnA 兼容 3E 帧)深度解析:从帧结构到 C++/Go 双语言采集实战
c语言·c++·golang
程序猿编码11 小时前
C++/CUDA 手写 LLM 推理引擎:拆解 vLLM 核心 PagedAttention 与连续批处理
开发语言·c++·深度学习·神经网络·推理·vllm
hold?fish:palm11 小时前
44 二叉搜索树中第K小的元素
开发语言·c++·算法