Problems with "CreateCompatibleBitmap"

Started by
1 comment, last by Vanz 15 years, 4 months ago
I'm creating some simple DC's and bitmaps, something like: hdcMap = CreateCompatibleDC(NULL); hMap = CreateCompatibleBitmap(hdc, 1920, 1200); SelectObject(hdcMap, hMap); The other day I noticed that on about my 7th bitmap, it would not create? When I copy to hdc I get just black and using the watch varaibles for this bitmap all the others turn from the value "0xcccccc" to some other value i.e. 0x6b205... etc, yet after defining 6 bitmaps the 7th one turned to "0x000000" and copied just black to the hdc (all this tells me when watching the variable is that it was created to zero result"... Was scratching my head for some time, as the 6 bitmaps before it were all defined the exact same way and worked fine, so I shut down my PC and restarted it, then everything worked fine... but now it's got me wondering what could have caused this?? Why wouldn't it create a bitmap? I though maybe I didn't delete it and it wasn't releasing for some reasone but sure enough I was: DeleteObject (hdcMap); DeleteObject (hMap); Hope that made sense, was a little hard to describe... Thoughts... I like to recreate bugs to make sure I have squashed them properly... rh
Advertisement
Obvious problems -

DC's are deleted with DeleteDC, not DeleteObject.

You are not saving the original bitmap after selecting the new one in - you need to select the old bitmap back into the hdc before deleting the hdc or the new bitmap.

You pass "NULL" to CreateCompatibleDC but "hdc" to CreateCompatibleBitmap. You should be passing the same hdc to both. If you need a dc/bitmap compatible with the screen use GetDC(NULL) to retrieve the original hdc. hdc's retrieved with GetDC are released with ReleaseDC, not DeleteDC.
-Mike
Hey thanks Anon Mike, I'll play with these and see if I can recreate the problem...

rh

This topic is closed to new replies.

Advertisement