HBRUSH CreatePatternBrush(hbmp) | ||||
HBITMAP hbmp; | /* handle of bitmap, */ |
The CreatePatternBrush function creates a brush whose pattern is specified by a bitmap. The brush can subsequently be selected for any device that supports raster operations.
hbmp
Identifies the bitmap.
The return value is the handle of the brush if the function is successful. Otherwise, it is NULL.
The bitmap identified by the hbmp parameter is typically created by using the CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, or LoadBitmap function.
Bitmaps used as fill patterns should be 8 pixels by 8 pixels. If the bitmap is larger, Windows will use the bits corresponding to only the first 8 rows and 8 columns of pixels in the upper-left corner of the bitmap.
An application can use the DeleteObject function to remove a pattern brush. This does not affect the associated bitmap, which means the bitmap can be used to create any number of pattern brushes. In any case, when the brush is no longer needed, the application should remove it by using DeleteObject.
A brush created by using a monochrome bitmap (one color plane, one bit per pixel) is drawn using the current text and background colors. Pixels represented by a bit set to 0 are drawn with the current text color, and pixels represented by a bit set to 1 are drawn with the current background color.
The following example loads a bitmap named Pattern, uses the bitmap to create a pattern brush in a call to the CreatePatternBrush function, selects the brush into a device context, and fills a rectangle by using the new brush:
HBITMAP hbmp;
HBRUSH hbr, hbrOld;
hbmp = LoadBitmap(hinst, "Pattern");
hbr = CreatePatternBrush(hbmp);
hbrOld = SelectObject(hdc, hbr);
Rectangle(hdc, 10, 10, 100, 100);
CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBPatternBrush, DeleteObject, GetDeviceCaps, LoadBitmap, SelectObject, SetBkColor, SetTextColor