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

相关推荐
Forget the Dream36 分钟前
设计模式之责任链模式
java·c++·设计模式·责任链模式
停止重构37 分钟前
【开源】低代码 C++程序框架,Linux多线程程序
c++·低代码·多线程·开源框架·云计算引擎
Duramentee40 分钟前
C++ 设计模式 十二:责任链模式 (读书 现代c++设计模式)
c++·设计模式·责任链模式
_GR1 小时前
Qt开发⑧Qt的窗口_下_浮动窗口+对话框
开发语言·css·c++·qt·microsoft
萌の鱼1 小时前
leetcode 3183. 达到总和的方法数量
数据结构·c++·算法·leetcode
Forget the Dream1 小时前
设计模式之代理模式
java·c++·设计模式·代理模式
攻城狮7号4 小时前
【第十节】C++设计模式(结构型模式)-Flyweight( 享元)模式
c++·设计模式·享元模式
Forget the Dream4 小时前
设计模式之享元模式
java·c++·设计模式·享元模式
溟洵8 小时前
【C/C++】理解C++内存与Linux虚拟地址空间的关系---带你通透C++中所有数据
linux·c语言·c++
Chandler2410 小时前
C++11 智能指针:unique_ptr、shared_ptr和weak_ptr 功能特性 模拟实现
开发语言·c++