他の画像形式をロードするために使用するコードを次に示します。GDI+ に依存しているため、使用前と使用後に初期化とシャットダウンが必要です (プログラムごとに 1 回で十分です)。
負荷ルーチン:
// BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF
HBITMAP mLoadImg(WCHAR *szFilename)
{
HBITMAP result=NULL;
Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFilename,false);
bitmap->GetHBITMAP(NULL, &result);
delete bitmap;
return result;
}
初期化/シャットダウン
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
static Gdiplus::GdiplusStartupInput gdiplusStartupInput;
static ULONG_PTR gdiplusToken;
// so we can load all the image formats that windows supports natively - (I'm using a transparent PNG on the main dialog)
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
// make things look pretty
InitCommonControls();
// run the app
//DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
//
//
//
// clean-up stuff
Gdiplus::GdiplusShutdown(gdiplusToken);
return 0;
}
当然のことながら、これはフレーム ベースのアプリや MFC アプリではなく、ダイアログ ベースのアプリ (ダイアログは resource.rc で定義されています) 用です。ポイントは、使用する前に初期化し、後でシャットダウンするだけです。