在程序中使用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. 




發佈了134 篇原創文章 · 獲贊 243 · 訪問量 54萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章