本文由CSDN用户zuishikonghuan所作,转载请注明出处:http://blog.csdn.net/zuishikonghuan/article/details/46982559
坚信GdiplusFlat比Gdiplus好!我要在资料匮乏的GdiplusFlat上打下一片天地!没有api文档?我去百度找,就算把那些其他不支持GDI+类的语言中用GdiplusFlat的例子翻出来看,头文件里函数和结构没有声明?我自己声明!实在不行?我把你们这些GdiplusFlat函数一个个从dll里load进来直接动态调用!!
GDI+(Gdiplus)想必大家都不陌生,MSDN给出的解释是
Windows GDI+ is a class-based API for C/C++ programmers. It enables applications to use graphics and formatted text on both the video display and the printer. Applications based on the Microsoft Win32 API do not access graphics hardware directly. Instead, GDI+ interacts with device drivers on behalf of applications. GDI+ is also supported by Microsoft Win64.
其实,这个GDI+是对GDI的进一步封装,GDI是Windows的图形设备接口,是以Win32API的形式提供的,完全是按照面向过程的思想使用的,而GDI+不一样,GDI+一开始就是提供的面向对象的编程方式,即提供的是GDI+类!在一个偶然的机会下,我知道了GDI+类的实现是调用的gdiplus.dll中的API,也就是说,GDI+是有API版本的,那么这个API版本,就是GdiplusFlat(GDI+平面API)!
这是微软的解释:
Windows GDI+ exposes a flat API that consists of about 600 functions, which are implemented in Gdiplus.dll and declared in Gdiplusflat.h. The functions in the GDI+ flat API are wrapped by a collection of about 40 C++ classes. It is recommended that you do not directly call the functions in the flat API. Whenever you make calls to GDI+, you should do so by calling the methods and functions provided by the C++ wrappers. Microsoft Product Support Services will not provide support for code that calls the flat API directly.
注意:如果使用GDI+平面API,微软不提供产品支持!!甚至这些平面API都没有文档化!!MSDN只是给了声明和简单说明
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的信息
#include "targetver.h"
#include "stdafx.h" #include <Windows.h>//windows头文件 #include <gdiplus.h>//GDI+头文件 #include <gdiplusflat.h>//GDI+Flat头文件 #pragma comment(lib,"gdiplus.lib")//这个非常重要 int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { }
typedef struct _GdiplusStartupInput{ unsigned int GdiplusVersion; unsigned int DebugEventCallback; BOOL SuppressBackgroundThread; BOOL SuppressExternalCodecs; }GdiplusStartupInput;
extern "C" int WINAPI GdiplusStartup(int* token,GdiplusStartupInput *input,int *output);
int token; int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { GdiplusStartupInput StartupInput; StartupInput.GdiplusVersion = 1; GdiplusStartup(&token, &StartupInput,NULL); }
extern "C" void WINAPI GdiplusShutdown(int token);
#include "stdafx.h" #include <Windows.h> #include <gdiplus.h> #include <gdiplusflat.h> #pragma comment(lib,"gdiplus.lib")//very important typedef struct _GdiplusStartupInput{ unsigned int GdiplusVersion; unsigned int DebugEventCallback; BOOL SuppressBackgroundThread; BOOL SuppressExternalCodecs; }GdiplusStartupInput; extern "C" int WINAPI GdiplusStartup(int* token,GdiplusStartupInput *input,int *output); extern "C" void WINAPI GdiplusShutdown(int token); int token; int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { //GDI+开启 GdiplusStartupInput StartupInput = {0}; StartupInput.GdiplusVersion = 1; GdiplusStartup(&token, &StartupInput,NULL); //在这里尽情地GDI+Flat编程吧 //GDI+关闭 GdiplusShutdown(token);//可以把这个写在消息循环后面,程序退出就销毁,或者在不需要GDI+时调用,比如GDI+窗口的WM_DESTROY消息里调用 }