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

相关推荐
啦啦啦!6 分钟前
c++AI大模型接入SDK项目
开发语言·数据结构·c++·人工智能·算法
cmpxr_20 分钟前
【C】隐式类型转换
c语言·c++·算法
大江东去浪淘尽千古风流人物30 分钟前
【Basalt】nfr_mapper 中的“小 SfM/BA 后端”
c++·人工智能·计算机视觉·oracle·augmented reality
Magic--30 分钟前
C++ STL中vector与list的核心区别
c++·windows·list
初願致夕霞32 分钟前
Linux_线程
linux·运维·服务器·c++
2401_8920709832 分钟前
【Linux C++ 后端实战】异步日志系统 AsyncLogging 完整设计与源码解析
linux·c++·高并发·异步日志
梓䈑34 分钟前
gtest实战入门:从安装到TEST宏的单元测试指南
c++·单元测试
郝学胜-神的一滴37 分钟前
墨韵技术|CMake:现代项目构建的「行云流水」之道
c++·程序人生·软件工程·软件构建·cmake
雪域迷影39 分钟前
Hazel游戏引擎结构分析
c++·游戏引擎·hazel
“愿你如星辰如月”40 分钟前
从零构建高性能 Reactor 服务器:
linux·服务器·c++·websocket·tcp/ip