Sign in to follow this  
BadEggGames

Why wont my win32 program paint?

Recommended Posts

Hi

 

I am trying to make my win32 program double buffer but it just wont display what i am drawing.

 

My code is:

case WM_ERASEBKGND:
		return 1;
	case WM_PAINT:
		GetClientRect(hwnd, &r);
		if (r.bottom == 0) {

			return;
		}
		int width = r.right - r.left;
		int height = r.top - r.bottom;

		// Get DC for window
		hdc = BeginPaint(hwnd, &ps);

		// Create an off-screen DC for double-buffering
		hdcMem = CreateCompatibleDC(hdc);
		hbmMem = CreateCompatibleBitmap(hdc, width, height);

		hOld = SelectObject(hdcMem, hbmMem);

		// Draw into hdcMem here
		for (int x = 0; x < 100; x++)
			for (int y = 0; y < 100; y++)
				SetPixel(hdcMem, x, y, RGB(255, 0, 0));

		// Transfer the off-screen DC to the screen
		BitBlt(hdc, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY);

		// Free-up the off-screen DC
		SelectObject(hdcMem, hOld);
		DeleteObject(hbmMem);
		DeleteDC(hdcMem);

		EndPaint(hwnd, &ps);
		return 0;

Any help would be greatly appreciated.

 

Thanks

Share this post


Link to post
Share on other sites

 

int height = r.top - r.bottom;



Just a stab in the dark, but that looks upside-down to me :-)

 

 

haha, yep 

 

for future reference, this is the correct way :P

GetClientRect(hwnd, &r);
		if (r.bottom == 0) {

			return;
		}
		width = r.right;
		height = r.bottom;

Share this post


Link to post
Share on other sites
Just a reminder:

Don't rely on rect's top and left members being zero. For simple GetClientRect it'll pretty much always be, but the safe approach would be the one you almost had before:

width = r.right - r.left;
height = r.bottom - r.top;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this