Skip to main content
gamedev.net
🔒 Locked

Win32 and Bitmaps

Started by FxMazter 3 replies 200+ views
Original Post
FxMazter
FxMazter
Hia! I have just started out with Win32 Programming. Ok, I'm stuck on loading bitmaps with GDI. This is how the function for drawing bitmaps looks: ------------------------------------------------------------- int DrawBitmapResource(HDC hDestDC, int xDest, int yDest, int nResID) { HBITMAP hBitmap; HDC hSrcDC; BITMAP bmp; int nWidth, nHeight; if((hBitmap = (HBITMAP)LoadImage(hInstance, MAKEINTRESOURCE(nResID), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)) == NULL) return(FALSE); if((hSrcDC = CreateCompatibleDC(NULL)) == NULL) return(FALSE); if(SelectObject(hSrcDC, hBitmap) == NULL) return(FALSE); if(GetObject(hBitmap, sizeof(BITMAP), &bmp)) return(FALSE); nWidth = bmp.bmWidth; nHeight = bmp.bmHeight; if(BitBlt(hDestDC, xDest, yDest, nWidth, nHeight, hSrcDC, 0, 0, SRCCOPY) == NULL) return(FALSE); DeleteDC(hSrcDC); return(TRUE); } ------------------------------------------------------------- and this is how I call for the function: ------------------------------------------------------------- DrawBitmapResource(hMainDC, 0, 0, 1002); ------------------------------------------------------------- hMainDC //a Device Context for the main window hInstance //handle to the main window 1002 //resource id for my bmp picture the problem is that when I try this, no errors occure... but the bitmap isn't shown either! (black screen is shown) Could someone tell me what I have made wrong? THX! [edited by - FxMazter on December 19, 2002 12:42:58 PM]
Zipster
Zipster
You have a destination DC, so when you call CreateCompatibleDC, you should pass that DC so that you''re sure it''s compatible.

What this function should be doing is un-selecting the bitmap from the context (by setting the old object back in) and then deleting the bitmap. And just for kicks, see if LR_DEFAULTCOLOR works as the last paramter to LoadImage.
Burning_Ice
Burning_Ice
the code works this way, CreateCompatibleDC(NULL) makes it compatible with the screen. The problem is in the line

if(GetObject(hBitmap, sizeof(BITMAP), &bmp))
return(FALSE);

this should be

if(GetObject(hBitmap, sizeof(BITMAP), &bmp) == 0)
return(FALSE);

i guess

currently you leave the function if the call succeeds and not if it fails



Runicsoft -- home of my open source Function Parser and more
FxMazter
FxMazter
Hey, Burning_ice that was the case!
great

Hehe, obviously it stated that if the Call was succesfull, then it should return false ^^

Kinda stupid of me ><
But when you sit many hours in straight with first reading and then trying to code it and understand, ur mind goes nuts ^^

Thank you

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.