CBitmap::CreateCompatibleBitmap

Syntax

BOOL CreateCompatibleBitmap( CDC* pDC, int nWidth, int nHeight );

Parameters

pDC

Specifies the device context.

nWidth

Specifies the width (in bits) of the bitmap.

nHeight

Specifies the height (in bits) of the bitmap.

Remarks

Initializes a bitmap that is compatible with the device specified by pDC. The bitmap has the same number of color planes or the same bits-per-pixel format as the specified device context. It can be selected as the current bitmap for any memory device that is compatible with the one specified by pDC.

If pDC is a memory device context, the bitmap returned has the same format as the currently selected bitmap in that device context. A “memory device context” is a block of memory that represents a display surface. It can be used to prepare images in memory before copying them to the actual display surface of the compatible device.

When a memory device context is created, GDI automatically selects a monochrome stock bitmap for it.

Since a color memory device context can have either color or monochrome bitmaps selected, the format of the bitmap returned by the CreateCompatibleBitmap function is not always the same; however, the format of a compatible bitmap for a nonmemory device context is always in the format of the device.

When you are finished with a CBitmap initialized with CreateCompatibleBitmap, you must select the bitmap out of the device context.

Return Value

TRUE if successful; otherwise FALSE.

See Also

::CreateCompatibleBitmap