CreateDIBitmap

  HBITMAP CreateDIBitmap(hdc, lpbmih, fdwInit, lpbInit, lpbmi, fuUsage)    
  HDC hdc; /* handle of device context */
  LPBITMAPINFOHEADER lpbmih; /* address of bitmap size- and format-data */
  DWORD fdwInit; /* initialization flag */
  CONST BYTE *lpbInit; /* address of initialization data */
  LPBITMAPINFO lpbmi; /* address of bitmap color-format data */
  UINT fuUsage; /* color-data usage flag */

The CreateDIBitmap function creates a device-dependent bitmap from a device-independent bitmap (DIB) and optionally sets the bitmap bits.

Parameters

hdc

Identifies a device context.

lpbmih

Points to a BITMAPINFOHEADER data structure. The BITMAPINFOHEADER structure has the following form:

typedef struct tagBITMAPINFOHEADER{ /* bmih */

DWORD biSize;

LONG biWidth;

LONG biHeight;

WORD biPlanes;

WORD biBitCount

DWORD biCompression;

DWORD biSizeImage;

LONG biXPelsPerMeter;

LONG biYPelsPerMeter;

DWORD biClrUsed;

DWORD biClrImportant;

} BITMAPINFOHEADER;

fdwInit

Specifies whether the function should use the data pointed to by lpbInit and lpbmi to initialize the bitmap. If the CBM_INIT bit is set, this data is used.

lpbInit

Points to an array of bytes that contains the initial bitmap data. The format of the data depends on the biBitCount member of the BITMAPINFO structure at which lpbmi points.

lpbmi

Points to a BITMAPINFO structure that describes the dimensions and color format of lpbInit. The BITMAPINFO structure has the following form:

typedef struct tagBITMAPINFO { /* bmi */

BITMAPINFOHEADER bmiHeader;

RGBQUAD bmiColors[1];

} BITMAPINFO;

fuUsage

Specifies whether the bmiColors member of the BITMAPINFO data structure was initialized and if so, whether bmiColors contains explicit RGB values or palette indices. The fuUsage parameter must be one of the following values:

Value Meaning

DIB_PAL_COLORS The color table is provided and consists of an array of 16-bit indices into the logical palette of the DC into which the bitmap will be selected.
DIB_PAL_INDICES There is no color table for the bitmap. The bitmap bits are indices into the device's physical palette, (not the currently selected logical palette).
DIB_RGB_COLORS The color table is provided and contains literal RGB values.

Return Value

The return value identifies the bitmap if the function is successful. Otherwise, it is NULL.

Comments

In order to obtain optimal bitmap drawing speed, the bitmap bits must be indices into the device's physical palette (and DIB_PAL_INDICES flag must be specified for the fuUsage argument). Applications that create bitmaps in this format must use the colors from the device's physical palette. These colors are obtained by calling the GetSystemPaletteEntries function. And, these colors are valid only when the application's window is the current active window. (For more information about color and palettes, see Chapter 70, “Colors and Color Palettes.”)

See Also

BITMAPINFO, BITMAPINFOHEADER, DeleteObject, GetDeviceCaps, GetSystemPaletteEntries, SelectObject