Jump to content
  • Advertisement
Sign in to follow this  
noNchaoTic

spot the problem...

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

Can anyone see why this isn't working?
HBITMAP	CopyBitmap(HBITMAP hbm, int Width, int Height, int BlitX, int BlitY)
{
	HDC Source = CreateCompatibleDC(NULL);
	HDC Destin = CreateCompatibleDC(NULL);
	
	HBITMAP	hbmOld, hbmOld2, hbmNew;
	BITMAP	bm;
			
	GetObject(hbm, sizeof(bm), &bm);

	hbmOld = (HBITMAP)SelectObject(Source, hbm);
	hbmNew = CreateBitmap(Width, Height, bm.bmPlanes, bm.bmBitsPixel, NULL);
	hbmOld2 = (HBITMAP)SelectObject(Destin, hbmNew);

	BitBlt(Destin, 0, 0, Width, Height, Source, BlitX, BlitY, SRCCOPY);
	
	SelectObject(Source, hbmOld);
	DeleteDC(Source);
	SelectObject(Destin, hbmOld2);
	DeleteDC(Destin);

	return hbmNew;
}
Im stumped :-(

Share this post


Link to post
Share on other sites
Advertisement
I can't see anything obviously wrong, but from experience, when something like this doesn't work, it's due to incompatible DCs and bitmaps.

Try specifying a DC in CreateCompatibleDC() and use CreateCompatibleBitmap() rather than create bitmap.

Use GetDC(GetDesktopWindow()) as your DC for these functions, just to be on the safe side.

Share this post


Link to post
Share on other sites
Quote:
Original post by noNchaoTic
So use the windows handle to get the handle to DC, and then use CreateCompatibleBitmap increate of just CreateBitmap?


Yes. Make sure you use the original DC and NOT the compatible DC in the call to CreateCompatibleBitmap though.

I'm not 100% sure this will fix your problem though. GDI can be kind of annoying in that things just silently fail with little or no useful feedback as to *why* they've failed, so it can take a bit of fiddling around and trial and error to get things working.

Share this post


Link to post
Share on other sites
Ok, its failing to create a Compatible DC from the HDC i get (using GetDC())when i first create the window... any ideas?

Share this post


Link to post
Share on other sites
Re-read your post, and am now using GetDesktopWindow(), getting a DC for that, and then using that to obtain a compatible DC. Its succeeding to obtain DCs for these, but still nothing... :-(

Share this post


Link to post
Share on other sites
When you're running it in debug mode, and are single stepping through, where does it fail? On which line?

Share this post


Link to post
Share on other sites
Thats just it, the function returns propertly, all the pointers !NULL. And in theory it worked... but in practice, i have no idea wtf is up. lol, Cheers for your time :-) If anyone else has any ideas i'd be very grateful for the suggestions.

Share this post


Link to post
Share on other sites
Quote:
Original post by noNchaoTic
Thats just it, the function returns propertly, all the pointers !NULL. And in theory it worked... but in practice, i have no idea wtf is up. lol, Cheers for your time :-) If anyone else has any ideas i'd be very grateful for the suggestions.


Yes, this is one of the annoying things about GDI, it gives you no feedback as to what's wrong.

I don't really know what to suggest beyond trial and error with different DCs and so on. Or if you like, post a zip of your project and I'll see if I can fix it when I've got a minute.

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!