The GdiplusStartup 作用是初始化GDI+函数库. CallGdiplusStartup before making any other GDI+ calls, and callGdiplusShutdown when you have finished using GDI+.
Status WINAPI GdiplusStartup( OUT ULONG_PTR *token, const GdiplusStartupInput *input, OUT GdiplusStartupOutput *output);
input
If the function succeeds, it returns Ok, which is an element of the Status enumeration.
If the function fails, it returns one of the other elements of the Status enumeration.
You must call GdiplusStartup before you create any GDI+ objects, and you must delete all of your GDI+ objects (or have them go out of scope) before you callGdiplusShutdown.
You can call GdiplusStartup on one thread and call GdiplusShutdown on another thread as long as you delete all of your GDI+ objects (or have them go out of scope) before you callGdiplusShutdown.
Do not call GdiplusStartup or GdiplusShutdown inDllMain or in any function that is called byDllMain. If you want to create a DLL that uses GDI+, you should use one of the following techniques to initialize GDI+:
For an example of calling GdiplusStartup and GdiplusShutdown in a Windows application, seeGetting Started.
The following console application uses a GDI+ Image object to retrieve the width and height of a JPEG image. The code callsGdiplusStartup before creating theImage object and callsGdiplusShutdown before terminating. Note that theImage object is deleted before the call toGdiplusShutdown.
In the following code, the variable gdiplusStartupInput is initialized by the default constructor of theGdiplusStartupInput structure. The default constructor sets the data members of the structure to the following values:
#include <windows.h> #include <gdiplus.h> #include <stdio.h> using namespace Gdiplus; INT main() { GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken; GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); Image* image = new Image(L"FakePhoto.jpg"); printf("The width of the image is %u./n", image->GetWidth()); printf("The height of the image is %u./n", image->GetHeight()); delete image; GdiplusShutdown(gdiplusToken); return 0; }
Windows NT/2000/XP: Included in Windows XP and Windows .NET Server.
Redistributable: Requires GDI+ on Windows NT 4.0 SP6; Windows 2000; and Windows 98/Me.
Header: Declared in Gdiplusinit.h; include Gdiplus.h.
Library: Use Gdiplus.lib. (!!!!!!!!!!!!!!!!记得在工程中加入此库,不然一大堆的报错)