Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Wed, 21 May 2008 06:12:01 -0700,    group: microsoft.public.win32.programmer.gdi        back       


CreateBitmap() & CreateCompatibleDC()   
The CreateBitmap definition in MSDN says that :

"After a bitmap is created, it can be selected into a device context by 
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 :

"A memory DC exists only in memory. When the memory DC is created, its 
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
date: Wed, 21 May 2008 06:12:01 -0700   author:   Belloc

Re: CreateBitmap() & CreateCompatibleDC()   
"Belloc"  wrote in message 
news:0D73AB69-6369-4EF3-95A1-D870F7621531@microsoft.com...
> The CreateBitmap definition in MSDN says that :
>
> "After a bitmap is created, it can be selected into a device context by
> 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 :
>
> "A memory DC exists only in memory. When the memory DC is created, its
> 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 ?


Both :)


>
> . 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.


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++



>
> . A memory DC, does it really have a default bitmap, or is it just a
> placeholder ?
>
> Microsoft Visual C++ .NET   69586-335-0000007-18101
>
date: Sun, 29 Jun 2008 13:41:42 -0700   author:   Mark Salsbery [MVP] MarkSalsbery[MVP]@newsgroup.nospam

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us