Question

I'm wondering , if I want to create different bitmaps,

I use the CreateCompatibleBitmap function again and again, to associate it to the same memory CDC.

is it the same meaning that I CreateBitmap and SelectObject again and again??

I ask this question because I want to do something to the newly created bitmap by another CDC.

Was it helpful?

Solution

Without seeing the specific code it's hard to know the exact problem but CreateCompatibleBitmap is commonly used in double-buffering situations to avoid flickering. Rather than drawing directly to the Device Context (DC) you first draw to an off-screen, or memory, DC which is basically drawing to a bitmap. The bitmap is then copied directly to the screen DC using BitBlt, so it appears like all the drawing happens at the same time.

The usual steps are this (and will probably happen on every WM_PAINT):

  1. Use the screen DC to create a bitmap, which is 'compatible' with it, using CreateCompatibleBitmap.
  2. Create a memory DC
  3. Select the bitmap into the memory DC (this is what you'll draw to)
  4. When drawing is finished BitBlt the memory DC's bitmap onto the screen DC.

More information available here: Guide to Win32 Memory DC (Code Project)

OTHER TIPS

Yes, CreateCompatibleBitmap() creates a new bitmap, a new memory allocation, a new handler each time you call it in a loop;

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top