CreateCompatibleDC
(1)
SelectObject
(1)
CreateBitmap
(1)
HDC
(1)
Belloc
(1)
D870F7621531
(1)
Depths
(1)
Bitmap
(1)

CreateBitmap() & CreateCompatibleDC()

Asked By Bello
21-May-08 09:12 AM
The CreateBitmap definition in MSDN says that :

calling the SelectObject() function. However, the bitmap can only be selected
into a device context if the bitmap and the DC have the same format".


The CreateCompatibleDC definition in MSDB say that :

display surface is exactly one monochrome pixel wide and one monochrome pixel
high".


If these two statements are correct, it would be impossible to select a
bitmap different than a monochrome bitmap into a memory DC, which clearly is
not the case, since that's the usual procedure to expand a memory DC, before
painting on it.


I've done some tests, selecting bitmaps obtained with CreateBitmap() and
with different color depths (bpp). The 1 and 32 bpp bitmaps are selected
normally by the function SelectObject(). For the other cases (4, 8, 16, 24)
the function fails.


Given the above contradictions, I have some conceptual questions :

. Which of the first two statements above is true ?

. Why does (4) occurs ?

. Given that a memory DC returned by CreateCompatibleDC(hDC) is different
from hDC, what is the meaning of  the term Compatible in the function's name
? At least one would expect this funtion to return a memory DC with the same
color organization as hDC.

. A memory DC, does it really have a default bitmap, or is it just a
placeholder ?

Microsoft Visual C++ .NET   69586-335-0000007-18101

CreateBitmap() & CreateCompatibleDC()

Asked By Mark Salsbery [MVP]
29-Jun-08 04:41 PM
Both :)




Compatible in pixel format.  The default monochrome 1x1 bitmap is a
placeholder.
A common mistake is to create a bitmap compatible with the memory DC
instead of the original DC, thus creating a monochrome bitmap.

I'm not sure why there's no error when a 1bpp bitmap is selected into a
32bpp DC...
probably the way it's always been.

Mark

--
Mark Salsbery
Microsoft MVP - Visual C++
Post Question To EggHeadCafe