An application can load the DIB driver by passing the DIB driver name and a BITMAPINFO structure containing the DIB bits to the CreateDC function. For example, the following example creates a DIB display context that represents the packed DIB described by the BITMAPINFO structure bi:
hdc = CreateDC("DIB", NULL, NULL, &bi);
An application must observe the following rules when working with a device context created in this manner:
If the last parameter of CreateDC is NULL, the display context is associated with a 0-by-0 8-bit DIB. Any attempt to draw with it will fail.
The BITMAPINFO structure must remain locked for the life of the device context.
The DIB driver supports 1-bit, 4-bit, or 8-bit DIB bitmaps. The run-length encoding (RLE) format is not supported.
The DIB driver supports only Windows version 3.0 or later DIB headers.
Multiple DIB-driver display contexts can be active.
DIBs reside in the memory-based image buffer in the CF_DIB (packed-DIB) format.
The DIB driver expects the RGBQUAD structure for color matching; it does not use palette indices. (If an application uses an RGB value for drawing, the DIB driver uses the closest match found in the color table of the DIB.)
The following example uses the DIB driver to draw a circle in a DIB copied from the clipboard:
if (IsClipboardFormatAvailable(CF_DIB) && OpenClipboard()) {
HANDLE hdib;
HDC hdc;
/* Get the DIB from the clipboard. */
hdib = GetClipboardData(CF_DIB);
/* Create a DIB driver hdc on the DIB surface. */
hdc = CreateDC("DIB", NULL, NULL,
(LPBITMAPINFO) GlobalLock(hdib));
/* Draw a circle in the DIB. */
Ellipse(hdc, 0, 0, 100, 100);
/* Delete the DIB driver HDC now that you are done with it. */
DeleteDC(hdc);
/* Unlock the DIB. */
GlobalUnlock(hdib);
/* Release the clipboard. */
CloseClipboard();
}