I've got a struct which contains a HBITMAP and want to be able to access the bitmap by it's handle from the array, but I have not been able to using GetObject in WM_PAINT. The program compiles and runs but won't show the bitmap. Any help is welcome.
I declare the handle to the bitmap at the top of the program and create the struct.
HBITMAP g_hbmChar = NULL;
struct character* current_character;
struct character {
char name [36];
char source [36];
char about [300];
HBITMAP cBitmap;
};
This is the array. I've cut it down for the sake of this example. The last element is supposed to be the bitmap.
struct character characters [13] =
{
{
"NAME", "SOURCE", "ABOUT", (HBITMAP)&g_hbmChar
}
};
I use LoadImage to load the bitmap in WM_CREATE.
g_hbmChar = LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDB_CHR1), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
Contents of WM_PAINT.
RECT rcClient;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
HDC HDCMem = CreateCompatibleDC(hdc);
GetClientRect(hWnd, &rcClient);
SelectObject(HDCMem, current_character->cBitmap);
BitBlt(hdc, 364, 26, 150, 190, HDCMem, 0, 0, SRCCOPY);
SelectObject(HDCMem, HDCMem);
DeleteDC(HDCMem);
EndPaint(hWnd, &ps);