Jump to content
  • Advertisement
Sign in to follow this  
superqtip182

Need help with StretchBlt

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

okay, so i've got my image working and loading... now i need to make it so that the image appears the same size as the dialog when i run the program and so that it resizes whenever i maximize the program... Here is what I have:
        case WM_INITDIALOG:
		{
			BITMAP bm;
			hBitmap = (HBITMAP)LoadImage(0,"page2.bmp",IMAGE_BITMAP,
					0, 0, 
					LR_LOADFROMFILE | LR_CREATEDIBSECTION | LR_DEFAULTSIZE);
		} 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 = (HBITMAP)SelectObject(hdcMem, hBitmap);

			GetObject(hBitmap, sizeof(bm), &bm);

			//BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
			StretchBlt(
				  hdc, 
				  100, 
				  0, 
				  bm.bmWidth * 2, 
				  bm.bmHeight * 2, 
				  hdcMem, 
				  50, 
				  0, 
				  bm.bmWidth, 
				  bm.bmHeight, 
				  SRCCOPY);

			SelectObject(hdcMem, hbmOld);
			DeleteDC(hdcMem);

			EndPaint(hWnd, &ps);
		}

Once again, no links please. I've gone all over MSDN, so that certainly won't help.

Share this post


Link to post
Share on other sites
Advertisement
in general what you do is:

RECT rect;
GetClientRect(hWnd, &rect);

that gets you the dimensions of your window. then you

int windowWidth = rect.right - rect.left;
int windowHeight = rect.bottom - rect.top;

then you use StretchBlt to stretch the bitmap to those dimensions.
i forgot how to use StretchBlt, but i think in your code you know
how to use it, ur just having trouble find what dimensions to
resize the bitmap to right?

Share this post


Link to post
Share on other sites
ha ha ha that's pretty cute u put that comment about
MessageBox and WM_PAINT. newbieeeee :P:P:P:P!!!! j/k

Share this post


Link to post
Share on other sites
Lol...

okay so it works initially, but the images colors are all messed up and i can make the image big when i first maximize the window, but when i make the window small, the image just stays the same size.

Share this post


Link to post
Share on other sites
where are you putting your call to GetClientRect?

RECT rect;
GetClientRect(hWnd, &rect);
int windowWidth = rect.right - rect.left;
int windowHeight = rect.bottom - rect.top;

should be right b4 your call to StrecthBlt. post your new code. also what kind of bitmap is page2.bmp? 24-bit? 32-bit? 8-bit or some other palette format?

Share this post


Link to post
Share on other sites
and you are using


StretchBlt(
hdc,
0,
0,
windowWidth, // i may have these values reversed (been long time he he he)
windowHeight,
hdcMem,
0,
0,
bm.bmWidth, // i may have these values reversed
bm.bmHeight,
SRCCOPY);

?

you have to be really careful if you decide to modify the (x,y) source and destination values. kind of hard to explain them without drawing a picture. unless i need to extract only a portion of the image, i leave those values at 0.

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!