Jump to content
  • Advertisement
Sign in to follow this  
Darobat

Why Doesnt My BMP Engine Work?

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

Greetings. I am trying to write a Bitmap engine, but I am so far Unsuccesful. It draws the bitmap, but it doesnt double buffer it (though it should be.) Heres the code that applies to the problem:
BOOL BMP::Draw(HDC hDC, UINT TransColor)
{
	HDC BuffDC;

	if(hDC == NULL)	// Make sure we are painting
	{
		MessageBox(NULL, "Invalid HDC", "Error", MB_OK | MB_ICONERROR);
		return FALSE;
	}

	BuffDC = CreateCompatibleDC(hDC);
	Bmp = (HBITMAP)SelectObject(BuffDC, Bitmap);

	// Draw it either with or without transparency
	if(TransColor == 0)
		BitBlt(hDC, X, Y, Width, Height, BuffDC, 0, 0, SRCCOPY);
	else
		TransparentBlt(hDC, X, Y, Width, Height,BuffDC, 
			0, 0, Width, Height, TransColor);

	DeleteDC(BuffDC);
	return TRUE;
}

void CreateMemDC(HDC &MemDC, HDC ScreenDC, UINT X, UINT Y)
{
	MemDC = CreateCompatibleDC(ScreenDC);
	Bmp = CreateCompatibleBitmap(ScreenDC, X, Y);
	SelectObject(MemDC, Bmp);
}

void DeleteMemDC(HDC &MemDC)
{
	DeleteDC(MemDC);
}



//////////////////////////
//...  In the WindowProc//
//////////////////////////
		case WM_CREATE:
			hDC = GetDC(hWnd);
				CreateMemDC(MemDC, hDC, 500, 500);
			ReleaseDC(hWnd, hDC);
		break;

		case WM_PAINT:
			MemDC = BeginPaint(hWnd, &ps);
				Test.Draw(MemDC, RGB(255, 0, 255));
				BitBlt(hDC, 0, 0, 500,500, MemDC, 0, 0, SRCCOPY);
			EndPaint(hWnd, &ps);
		break;

It draws, but if I comment out BitBlt(hDC, 0, 0, 500,500, MemDC, 0, 0, SRCCOPY); in WM_PAINT, it still draws. Anyone know why?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Are you supposed to be calling this line in the WM_PAINT case?

Test.Draw(MemDC, RGB(255, 0, 255));

You call that line, which by the looks from your code will draw the bitmap. Then you call the BitBlt which will do the same thing...

Share this post


Link to post
Share on other sites
It isn't double buffered. You draw straight to the DC returned by BeginPaint(which is the HDC of the window, probably equal to the hDC variable) inside BMP::Draw.

You most likely should not be resetting MemDC inside WM_PAINT, because the HDC returned by BeginPaint is not a memory DC (it is the DC of the window just like hDC).

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.

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!