CreateBrushIndirect Function
The CreateBrushIndirect function creates a logical brush with the specified style, color, and pattern. A logical brush is a GDI object that can be selected into a device context (DC) to fill areas with colors, patterns, or bitmaps.
Syntax
HBRUSH CreateBrushIndirect(
<a href="#logbrush">const LOGBRUSH</a> *lplb
);
Parameters
| Parameter | Description |
|---|---|
lplb |
A pointer to a |
Return Value
If the function succeeds, the return value is a handle to the newly created logical brush. If the function fails, the return value is NULL.
To get extended error information, call GetLastError.
Remarks
A brush is used for drawing windows and other client-area elements. The system maintains a cache of recently used brushes. If an application requests a brush that is identical to a brush already in the cache, the system returns a handle to the cached brush. Otherwise, it creates a new brush.
After you no longer need a brush, you should delete it by calling the DeleteObject function. This frees up system resources.
The LOGBRUSH structure specifies the characteristics of the brush:
lbStyle: The style of the brush. This can be one of the following values:BS_SOLID: A solid brush.BS_PATTERN: A pattern brush. The brush is a bitmap specified by thelbBitmapmember.BS_NULL: A null, or transparent, brush.BS_HATCHED: A hatched brush.
lbColor: The color of the brush. IflbStyleisBS_PATTERN, this member is ignored.lbHatch: The hatch pattern for a hatched brush. This member is ignored unlesslbStyleisBS_HATCHED.
BS_PATTERN, the lbBitmap member of the LOGBRUSH structure should point to a bitmap created by the CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, or LoadBitmap function.
Structures
LOGBRUSH Structure
typedef struct tagLOGBRUSH {
UINT lbStyle;
COLORREF lbColor;
LONG lbHatch;
} LOGBRUSH;
lbStyle: Specifies the brush style. See theCreateBrushIndirectremarks for possible values.lbColor: Specifies the color of the brush in the form of aCOLORREFvalue.lbHatch: Specifies the hatch pattern for hatched brushes.