Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Fredric

Displaying a bmp in Windows

This topic is 6935 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having an awful time trying to get this .bmp to show up in a window that I made. The following is the .rc file... //MyBp.rc MyBp BITMAP MyBp.bmp Correct me if I'm wrong, but the above is the correct way to make a bitmap .rc file, right? Anyhow, the following is the WinProc which handles WM_PAINT, WM_CREATE and WM_DESTROY which all relate to the bitmap I'm working with. LRESULT CALLBACK WinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc, memdc; // handles to the device context PAINTSTRUCT ps; switch(message){ case WM_CREATE: // hbit becomes the handle to MyBp hbit = LoadBitmap(hInst, "MyBp"); break; case WM_PAINT: hdc = BeginPaint(hwnd, &ps); memdc = CreateCompatibleDC(hdc); SelectObject(memdc, hbit); // select the bitmap to be drawn BitBlt(hdc, 0, 0, 256, 128, memdc, 0, 0, SRCCOPY); // display the image BitBlt(hdc, 300, 100, 256, 128, memdc, 0, 0, SRCCOPY); // display a 2nd bitmap EndPaint(hwnd, &ps); // realse the DC DeleteDC(memdc); // free the memory context break; case WM_DESTROY: // terminate the program DeleteObject(hbit); PostQuitMessage(0); break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; } What the heck am I doing wrong? The application compiles without any errors, but when the window pops up, all I can see are two very small dots in the coordinates where the images should be. Can anyone help? GO LEAFS GO! Edit: Oh yah, hbit and hInst were declared with the following: HBITMAP hbit; HINSTANCE hInst; Edited by - Fredric on 4/26/00 8:17:19 PM

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I can´t find any bugs in the code you show me:
But try to set a breakpoint after the load of the bitmap,
and check if the image gets loaded correct (hbit != NULL)

Is hbit declared gloabal or inside WinProc? If it´s inside make sure to make it static.

Also the use of LoadBitmap is bad, because LoadBitmap() has problem with big images (and a lot of other things).

Instead use LoadImage(); it gives you much more control.

Share this post


Link to post
Share on other sites
hey! i had the exact same problem, but i figured it out! here''s what you could be doing wrong:

The MyBp file has to be created and ACTUALLY ATTACHED to the EXE. It can''t just contain a filename and expect windows to load it for you, no, it wont do that . You have to use VC++''s little image editor for this. It would be greatly easier to load the file externally with LoadImage, since you also have the full power of any editor you chose, and not just the crappy VC++ image editor. You simply go to (on the menu), Insert->Resource->Custom... and enter BITMAP when it asks for the name of the resourse. Of course, things get only more confusing from there, so just load the file externally. Heres the code:

CBitmap Bitmap; // this is what holds the bitmap.
HBITMAP hBitmap; // handle used to load bitmap.

hBitmap = LoadImage(/*Forgot what parameters go here, one is filename, one is some flags, look it up */);

Bitmap.DeleteObject(); //DING DING DING, if you don''t want an assert error on the second load, do this
Bitmap.Attach (hBitmap); // attaches bitmap to object

This is how you would load it, and Bitmap now contains the bitmap. you then can use bitblt to blit it to the screen.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!