The document is archived and information here might be outdated


Initializes a device-dependent memory bitmap that has the specified width, height, and bit pattern.

BOOL CreateBitmap(
   int nWidth,
   int nHeight,
   UINT nPlanes,
   UINT nBitcount,
   const void* lpBits 



Specifies the width (in pixels) of the bitmap.


Specifies the height (in pixels) of the bitmap.


Specifies the number of color planes in the bitmap.


Specifies the number of color bits per display pixel.


Points to a short-integer array that contains the initial bitmap bit values. If it is NULL, the new bitmap is left uninitialized.

Nonzero if successful; otherwise 0.

For a color bitmap, either the nPlanes or nBitcount parameter should be set to 1. If both of these parameters are set to 1, CreateBitmap creates a monochrome bitmap.

Although a bitmap cannot be directly selected for a display device, it can be selected as the current bitmap for a "memory device context" by using CDC::SelectObject and copied to any compatible device context by using the CDC::BitBlt function.

When you finish with the CBitmap object created by the CreateBitmap function, first select the bitmap out of the device context, then delete the CBitmap object.

For more information, see the description of the bmBits field in the BITMAP structure. The BITMAP structure is described under the CBitmap::CreateBitmapIndirect member function.

© 2016 Microsoft