Click to See Complete Forum and Search --> : Loading bitmap won't work??


WhorlyWhelk
September 5th, 2007, 10:09 PM
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.

olivthill
September 6th, 2007, 08:08 AM
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.

Krishnaa
September 6th, 2007, 08:29 AM
Whats gra1 ?? You should supply the correct resource ID there.

g3RC4n
September 7th, 2007, 11:05 PM
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?

WhorlyWhelk
September 9th, 2007, 06:29 PM
Thanks g3RC4n it works when I change MAKEINTRESOURCE(gra1) to TEXT("gra1") instead though I don't know why. :-)