Skip to main content
GameDev.net gamedev.net
🔒 Locked

Need help with StretchBlt

Started by superqtip182 Jun 13, 2007 at 7:54 PM 10 replies 1.4k views
Original Post
superqtip182
superqtip182
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.
Yes, sir, I AM a female programmer.
yadango
yadango
in general what you do is:

RECT rect;
GetClientRect(hWnd, ▭);

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?
superqtip182
superqtip182
Explain, please.
Yes, sir, I AM a female programmer.
yadango
yadango
ha ha ha that's pretty cute u put that comment about
MessageBox and WM_PAINT. newbieeeee :P:P:P:P!!!! j/k
superqtip182
superqtip182
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.
Yes, sir, I AM a female programmer.
yadango
yadango
where are you putting your call to GetClientRect?

RECT rect;
GetClientRect(hWnd, ▭);
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?
superqtip182
superqtip182
The new code is in the correct spot.

page2.bmp is a 24-bit.
Yes, sir, I AM a female programmer.
yadango
yadango
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.
superqtip182
superqtip182
I am using that exact code. Here are some images:

Here is the initial run:


When I maximize it:


When I make it smaller again:

Yes, sir, I AM a female programmer.
yadango
yadango
ah, if i remember right that's because WM_PAINT isn't called when a restore is done. i think in WM_SYSCOMMAND you have to respond to SC_RESTORE, and call InvalidateRect(hWnd, 0, FALSE);

so maybe something like:

case WM_SYSCOMMAND:     if(wParam == SC_RESTORE) InvalidateRect(hWnd, 0, FALSE);     break;


EDIT: then again, a WM_SIZE should still be generated in a restore, so in WM_SIZE you can also call InvalidateRect(hWnd, 0, FALSE). this would probably be better solution.
Endurion
Endurion
Did you call SetStretchBltMode with COLORONCOLOR?
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Topic Locked

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

Sign in to reply to this topic.