HBITMAP CreateBitmapIndirect(lpbm) | |||||
BITMAP FAR* lpbm; | /* address of structure with bitmap information | */ |
The CreateBitmapIndirect function creates a bitmap that has the width, height, and bit pattern specified in a BITMAP structure.
lpbm
Points to a BITMAP structure that contains information about the bitmap. The BITMAP structure has the following form:
typedef struct tagBITMAP { /* bm */
int bmType;
int bmWidth;
int bmHeight;
int bmWidthBytes;
BYTE bmPlanes;
BYTE bmBitsPixel;
void FAR* bmBits;
} BITMAP;
For a full description of this structure, see the Microsoft Windows Programmer's Reference, Volume 3.
The return value is the handle of the bitmap if the function is successful. Otherwise, it is NULL.
Large bitmaps cannot be displayed on a display device by copying them directly to the device context for that device. Instead, applications should create a memory device context that is compatible with the display device, select the bitmap as the current bitmap for the memory device context, and then use a function such as BitBlt or StretchBlt to copy it from the memory device context to the display device context. (The PatBlt function can copy the bitmap for the current brush directly to the display device context.)
When an application has finished using the bitmap created by the CreateBitmapIndirect function, it should select the bitmap out of the device context and then delete the bitmap by using the DeleteObject function.
If the BITMAP structure pointed to by the lpbm parameter has been filled in by using the GetObject function, the bits of the bitmap are not specified, and the bitmap is uninitialized. To initialize the bitmap, an application can use a function such as BitBlt or SetDIBits to copy the bits from the bitmap identified by the first parameter of GetObject to the bitmap created by CreateBitmapIndirect.
The following example assigns values to the members of a BITMAP structure and then calls the CreateBitmapIndirect function to create a bitmap handle:
BITMAP
bm; HBITMAP hbm; int aZigzag[] = { 0xFF, 0xF7, 0xEB, 0xDD, 0xBE, 0x7F, 0xFF, 0xFF }; bm.bmType = 0; bm.bmWidth = 8; bm.bmHeight = 8; bm.bmWidthBytes = 2; bm.bmPlanes = 1; bm.bmBitsPixel = 1; bm.bmBits = aZigzag; hbm = CreateBitmapIndirect(&bm);
BitBlt, CreateBitmap, CreateCompatibleBitmap, CreateDIBitmap, CreateDiscardableBitmap, DeleteObject, GetObject