在程序中使用GDI+的步骤
Posted 善良超锅锅
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在程序中使用GDI+的步骤相关的知识,希望对你有一定的参考价值。
使用之前,你必须做下面5个步骤:
(1)创建一个工程,引入GDI+头文件
#include <GdiPlus.h>
(2)使用GDI+命名空间
using namespace Gdiplus;
要不然会出现很多未定义符号的错误
(3)引入Gdiplus.lib库
#pragma comment(lib,"Gdiplus.lib")
要不然编译时会出现找不到实现的错误
(4)在使用前初始化GDI+系统资源
一般是在app类的初始化方法中
ULONG_PTR gdiplusToken;//得保证这个变量在释放GDI+资源时也能访问得到,一般设为全局变量
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&gdiplusToken,&gdiplusStartupInput,NULL);
(5)使用完毕后,释放GDI+系统资源
一般是在app类的析构函数中或者ExitInstance函数中或者Instance函数末尾中调用
GdiplusShutdown(gdiplusToken);
GDI+的使用:
通常,你需要创建一个Graphics对象来使用GDI+提供的各种绘图函数。
构造函数:
The Graphics class has these constructors.
Constructor | Description |
---|---|
Graphics::Graphics(HDC) | Creates a Graphics::Graphics object that is associated with a specified device context. |
Graphics::Graphics(HDC,HANDLE) | Creates a Graphics::Graphics object that is associated with a specified device context and a specified device. |
Graphics::Graphics(HWND,BOOL) | Creates a Graphics::Graphics object that is associated with a specified window. |
Graphics::Graphics(Image*) | Creates a Graphics::Graphics object that is associated with an Image object. |
除了上面的构造函数外,还有Graphics类提供了下面几个静态函数。它们更好用。
Graphics::FromHDC(HDC) | The Graphics::FromHDC method creates a Graphics object that is associated with a specified device context. |
Graphics::FromHDC(HDD,HANDLE) | The Graphics::FromHDC method creates a Graphics object that is associated with a specified device context and a specified device. |
Graphics::FromHWND | The Graphics::FromHWND method creates a Graphics object that is associated with a specified window. |
Graphics::FromImage | The Graphics::FromImage method creates a Graphics object that is associated with a specifiedImage object. |
以上是关于在程序中使用GDI+的步骤的主要内容,如果未能解决你的问题,请参考以下文章