Jump to content
  • Advertisement
Sign in to follow this  
violetann

painting/loading 2 diffrent bitmaps

This topic is 4865 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

ok i've been playing around with loading bitmaps, in windows app, i've got one to load fine but the second is tricky it keeps loading the first image instead of the first, i think it's to do with the "HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);" if i change the g_hbmBall to g_hbmcup it loads the cup image in the two places. can anyone tell me how to get it to load the two diffrent ones or have an address to somewhere which dose? case WM_CREATE: g_hbmBall = LoadBitmap(GetModuleHandle(NULL), KEINTRESOURCE(IDB_BALL)); g_hbmcup = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_cup)); if(g_hbmBall == NULL) MessageBox(hwnd, "Could not load IDB_BALL!", "Error", MB_OK | MB_ICONEXCLAMATION); break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_PAINT: { // Just a note, never use a MessageBox from inside WM_PAINT // The box will cause more WM_PAINT messages and you'll probably end up // stuck in a loop BITMAP bm; PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); HDC hdcMem = CreateCompatibleDC(hdc); HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall); GetObject(g_hbmBall, sizeof(bm), &bm); BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY); GetObject(g_hbmcup, sizeof(bm), &bm); BitBlt(hdc, 20, 20, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, hbmOld); DeleteDC(hdcMem); EndPaint(hwnd, &ps); } break; case WM_DESTROY: DeleteObject(g_hbmBall); DeleteObject(g_hbmcup); PostQuitMessage(0); break;

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Well, you've almost answered your own question. You are selecting the ball bitmap into your memory hdc. So, when you call BitBlt, that's the image it's going to blit. You need to break it down into two steps. First, select the ball bitmap into hdcMem and BitBlt. Then, select the cup bitmap into hdcMem and BitBlt again.

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Well, you've almost answered your own question. You are selecting the ball bitmap into your memory hdc. So, when you call BitBlt, that's the image it's going to blit. You need to break it down into two steps. First, select the ball bitmap into hdcMem and BitBlt. Then, select the cup bitmap into hdcMem and BitBlt again.


That was me. I got logged out unexpectedly.

Share this post


Link to post
Share on other sites
humm so something like:

HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);
GetObject(g_hbmBall, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);


HBITMAP hbmOld = SelectObject(hdcMem, g_hbmcup);
GetObject(g_hbmcup, sizeof(bm), &bm);
BitBlt(hdc, 20, 20, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

i'll have to double check when i get home on my compiler.

Share this post


Link to post
Share on other sites
Well, actually:


HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmBall);
GetObject(g_hbmBall, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

//No need to store return value here as it's stored above
SelectObject(hdcMem, g_hbmcup);
GetObject(g_hbmcup, sizeof(bm), &bm);
BitBlt(hdc, 20, 20, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

//Restore old value
SelectObject (hdcMem, hbmOld);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!