CreateBrushIndirect

2.x

  HBRUSH CreateBrushIndirect(lplb)    
  LOGBRUSH FAR* lplb; /* address of structure with brush attributes */

The CreateBrushIndirect function creates a brush that has the style, color, and pattern specified in a LOGBRUSH structure. The brush can subsequently be selected as the current brush for any device.

Parameters

lplb

Points to a LOGBRUSH structure that contains information about the brush. The LOGBRUSH structure has the following form:

typedef struct tagLOGBRUSH {    /* lb */
    UINT     lbStyle;
    COLORREF lbColor;
    int      lbHatch;
} LOGBRUSH;

For a full description of this structure, see the Microsoft Windows Programmer's Reference, Volume 3.

Return Value

The return value is the handle of the brush if the function is successful. Otherwise, it is NULL.

Comments

A brush created by using a monochrome (one plane, one bit per pixel) bitmap is drawn by 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.

When it has finished using a brush created by CreateBrushIndirect, an application should select the brush out of the device context in which it was used and then remove the brush by using the DeleteObject function.

Example

The following example creates a hatched brush with red diagonal hatch marks and uses that brush to fill a rectangle:

LOGBRUSH lb;
HBRUSH hbr, hbrOld;

lb.lbStyle = BS_HATCHED;
lb.lbColor = RGB(255, 0, 0);
lb.lbHatch = HS_BDIAGONAL;

hbr = CreateBrushIndirect(&lb);
hbrOld = SelectObject(hdc, hbr);
Rectangle(hdc, 0, 0, 100, 100);

See Also

CreateDIBPatternBrush, CreatePatternBrush, CreateSolidBrush, DeleteObject, GetStockObject, SelectObject