если в MFC , то пользовать конструкторы CBrush
CBrush(
int nIndex,
COLORREF crColor
);
explicit CBrush(
CBitmap* pBitmap
);
Parameters
crColor
Specifies the foreground color of the brush as an RGB color. If the brush is hatched, this parameter specifies the color of the hatching.
nIndex
Specifies the hatch style of the brush. It can be any one of the following values:
HS_BDIAGONAL Downward hatch (left to right) at 45 degrees
HS_CROSS Horizontal and vertical crosshatch
HS_DIAGCROSS Crosshatch at 45 degrees
HS_FDIAGONAL Upward hatch (left to right) at 45 degrees
HS_HORIZONTAL Horizontal hatch
HS_VERTICAL Vertical hatch
pBitmap
Points to a CBitmap object that specifies a bitmap with which the brush paints.
Example
void CBrushView::OnDraw(CDC* pDC)
{
CBrushDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// CBrush::CBrush.
CBrush brush1; // Must initialize!
brush1.CreateSolidBrush(RGB(0,0,255)); // Blue brush.
CBrush* pTempBrush = NULL;
CBrush OrigBrush;
CRect rc;
GetClientRect(&rc);
ScreenToClient(&rc);
pTempBrush = (CBrush*)pDC->SelectObject(&brush1);
// Save original brush.
OrigBrush.FromHandle((HBRUSH)pTempBrush);
// Paint upper left corner with blue brush.
pDC->Rectangle(0, 0, rc.Width() / 2, rc.Height() / 2);
// These constructors throw resource exceptions.
try
{
// CBrush::CBrush(COLORREF crColor)
CBrush brush2(RGB(255,0,0)); // Solid red brush.
// CBrush::CBrush(int nIndex, COLORREF crColor)
// Hatched green brush.
CBrush brush3(HS_DIAGCROSS, RGB(0,255,0));
// CBrush::CBrush(CBitmap* pBitmap)
CBitmap bmp;
// Load a resource bitmap.
bmp.LoadBitmap(IDB_BRUSH);
CBrush brush4(&bmp);
pTempBrush = (CBrush*)pDC->SelectObject(&brush2);
// Paint upper right corner with red brush.
pDC->Rectangle(rc.Width() / 2, 0, rc.Width(),
rc.Height() / 2);
pTempBrush = (CBrush*)pDC->SelectObject(&brush3);
// Paint lower left corner with green hatched brush.
pDC->Rectangle(0, rc.Height() / 2, rc.Width() / 2,
rc.Height());
pTempBrush = (CBrush*)pDC->SelectObject(&brush4);
// Paint lower right corner with resource brush.
pDC->Rectangle(rc.Width() / 2, rc.Height() / 2,
rc.Width(), rc.Height());
}
catch(CResourceException* e)
{
e->ReportError();
e->Delete();
}
// Reselect original brush into device context.
pDC->SelectObject(&OrigBrush);
}