Re: CreateCompatibleBitmap
The DC does not have a width or height. It is just an interface for drawing onto a surface.
You have to use some other method to get the dimensions of the window etc. that the DC draws onto.
Re: CreateCompatibleBitmap
Isn't there a bitmap that is associated with a DC? If so, is there a way for me to access it so that I can get the width and height of the bitmap?
Re: CreateCompatibleBitmap
You might be able to use GetCurrentObject to get the currently selected bitmap.
Viggy
Re: CreateCompatibleBitmap
Quote:
Originally Posted by
links
Isn't there a bitmap that is associated with a DC? If so, is there a way for me to access it so that I can get the width and height of the bitmap?
Not necessarily. A DC with a bitmap is called a memory DC.
Re: CreateCompatibleBitmap
Thanks for all the replies. You guys are really helpful.
Re: CreateCompatibleBitmap
Quote:
Originally Posted by
zerver
A DC with a bitmap is called a memory DC.
:confused::confused::confused:
I have to admit, this is confusing. Could you elaborate?
Re: CreateCompatibleBitmap
Quote:
Originally Posted by
JohnCz
:confused::confused::confused:
I have to admit, this is confusing. Could you elaborate?
Well, if I'm not completely mistaken a DC normally draws directly to screen. For instance, GetDC(NULL) will obtain a DC that draws directly on top of the entire screen surface. Such a DC does not have an associated bitmap, and GetCurrentObject would not return anything useful.
If you select a bitmap into the DC, it will draw onto this bitmap instead. Common uses for this are double-buffering (to reduce flicker), but also to generate an image that can be saved to disk. The reason it is called memory DC is that it draws into computer memory rather than a graphics buffer. However, this is not entirely true since device dependent bitmaps very well may be uploaded to the graphics memory for video acceleration purposes. This is done transparently by the system and graphics drivers.
Re: CreateCompatibleBitmap
Quote:
Originally Posted by
zerver
A DC with a bitmap is called a memory DC.
Well you stated that DC with bitmap is called memory DC. Not necessarily. You can select bitmap to a window’s device context directly and use it to transfer image.
CreteCompatibleDC, creates device context compatible with window’s device context, in memory; this constitutes so called memory DC or buffer DC. Memory DC is not a specific name that is used for a categorization - it is just most popular.
Created buffer can be used to reduce flickering by transferring image to a buffer, do some drawing and transfer all to a Windows DC. It is also used to store temporally window’s device context to display something else and return to original context.
Re: CreateCompatibleBitmap
Quote:
Originally Posted by
JohnCz
You can select bitmap to a window’s device context directly and use it to transfer image.
Are you sure?
According to MSDN:
Bitmaps can be selected for memory device contexts only, and for only one device context at a time.
Re: CreateCompatibleBitmap
Quote:
Originally Posted by
VladimirF
Are you sure?
Well, not anymore. That happens when posting without testing. I could have sworn, that I had an application where I selected a bitmap directly to a windows dc, however after finding it, I realized I used BitBlt.
Thanks for correcting and sorry for a confusion.
Re: CreateCompatibleBitmap
Quote:
Originally Posted by
VladimirF
Are you sure?
According to
MSDN:
Bitmaps can be selected for memory device contexts only, and for only one device context at a time.
This is correct, although it is possible to work around by creating two device independent bitmaps that share the same pixel memory.