Loading bitmap wont work?

case WM_PAINT:
{
HDC hdc2,mdc;
HBITMAP bmp;
PAINTSTRUCT ps2;
HFONT font14,font18,font60;
hdc2=BeginPaint(hwnd,&ps2);
mdc=CreateCompatibleDC(hdc2);
bmp=LoadBitmap(GetWindowInstance(hwnd),MAKEINTRESOURCE(gra1));
SelectObject(mdc,bmp);
BitBlt(hdc2,20,5,12,6,mdc,0,0,SRCCOPY);
...
...
...

in resource.h...
#define gra1 41

in proj.rc...
gra1 BITMAP DISCARDABLE "thepic.bmp"

Doesn't work. No matter what I do bmp is always NULL right after I call either LoadBitmap or LoadImage.

Any idea?

Oh... it works when I just load the file not through the resource... :=|

Thanks for any help.
[826 byte] By [WhorlyWhelk] at [2007-11-20 10:33:28]
# 1 Re: Loading bitmap wont work?
mdc=CreateCompatibleDC(hdc2);A DC is created.
If I remember well, a DC has an empty bitmap by default, and therefore CreateCompatibleDC() should be followed by a call to CreateCompatibleBitmap(), except in some special cases.
olivthill at 2007-11-9 13:32:04 >
# 2 Re: Loading bitmap wont work?
Whats gra1 ?? You should supply the correct resource ID there.
Krishnaa at 2007-11-9 13:33:04 >
# 3 Re: Loading bitmap wont work?
your resource files fine

this is how i load and display bitmaps

static HBITMAP hbitmap;
WM_CREATE:
hBitmap= LoadBitmap (hInstance, TEXT ("BITMAP_ID"));
return 0;

WM_PAINT:
hdc = BeginPaint (hWnd, &ps) ;
hdcMem = CreateCompatibleDC (hdc) ;
SelectObject (hdcMem, hBitmap);
BitBlt(hdc, X_POS,Y_POS,X_SIZE,Y_SIZE, hdcMem, 0,0, SRCCOPY);
DeleteDC (hdcMem) ;
EndPaint (hWnd, &ps) ;
return 0;

case WM_PAINT:
{
HDC hdc2,mdc;
HBITMAP bmp;
PAINTSTRUCT ps2;
HFONT font14,font18,font60;
hdc2=BeginPaint(hwnd,&ps2);
mdc=CreateCompatibleDC(hdc2);
bmp=LoadBitmap(GetWindowInstance(hwnd),TEXT("gra1"));
SelectObject(mdc,bmp);
BitBlt(hdc2,20,5,12,6,mdc,0,0,SRCCOPY);
DeleteDC (mdc);
EndPaint (hwnd, &ps2) ;
return 0;
}

i just changed the loadbitmap() function, although i can't see why you have to use getwindowinstance(), surly you have the instance from the callback arguments?
g3RC4n at 2007-11-9 13:34:13 >
# 4 Re: Loading bitmap wont work?
Thanks g3RC4n it works when I change MAKEINTRESOURCE(gra1) to TEXT("gra1") instead though I don't know why. :-)
WhorlyWhelk at 2007-11-9 13:35:06 >