Bitmap.Bitmap(HINSTANCE, const WCHAR*) constructor
Applies to: desktop apps only
Creates a Bitmap::Bitmap object based on an application or DLL instance handle and the name of a bitmap resource.
Syntax
Bitmap(
[in] HINSTANCE hInstance,
[in] const WCHAR *bitmapName
);
Parameters
hInstance [in]
Type: HINSTANCEHandle to an instance of a module whose executable file contains a bitmap resource.
bitmapName [in]
Type: const WCHAR*Pointer to a null-terminated string that specifies the path name of the bitmap resource to be loaded. Alternatively, this parameter can consist of the resource identifier in the low-order word and zero in the high-order word. You can use the MAKEINTRESOURCE macro to create this value.
Examples
The following example creates a Bitmap::Bitmap object based on an application instance handle and the name of a bitmap resource. Assume that the code is compiled into an executable file that contains a bitmap resource named BitmapResource1. The WinMain function receives the instance handle of the running application and stores that handle in a global variable g_hInstance. The WndProc function (in response to a WM_PAINT message) constructs a Bitmap object based on the handle stored in g_hInstance and the name of the bitmap resource. The call to Graphics::DrawImage draws the bitmap on the screen.
HINSTANCE g_hInstance;
INT WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE, PSTR szCmdLine, INT iCmdShow)
{
g_hInstance = hInstance;
}
LRESULT CALLBACK
WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
Graphics* pGraphics;
Bitmap* pBitmap;
switch(message)
{
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
pGraphics = new Graphics(hdc);
pBitmap = new Bitmap(g_hInstance, L"BitmapResource1");
pGraphics->DrawImage(pBitmap, 10, 10);
delete pBitmap;
delete pGraphics;
EndPaint(hWnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
Requirements
Minimum supported client |
Windows XP, Windows 2000 Professional |
Minimum supported server |
Windows 2000 Server |
Product |
GDI+ 1.0 |
Header |
Gdiplusheaders.h (include Gdiplus.h) |
Library |
Gdiplus.lib |
DLL |
Gdiplus.dll |
See also
Using Images, Bitmaps, and Metafiles
Images, Bitmaps, and Metafiles
Send comments about this topic to Microsoft
Build date: 3/6/2012