Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 8 GDI Orientation and Transformations


7.6.5 Logical Brushes....................................................................................


The Win32 library provides the LOGBRUSH structure that can be used to create a brush
by specifying its characteristics. LOGBRUSH is defined as follows:

typedef struct tagLOGBRUSH {
UINT lbStyle;
COLORREF lbColor;
LONG lbHatch;
} LOGBRUSH, *PLOGBRUSH;

The lbStyle member variable specifies the style applied on the brush.
The lbColor is specified as a COLORREF value.
The lbHatch value represents the hatch pattern used on the brush.
Here is an example:

void CExoView::OnDraw(CDC* pDC)
{
CExoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CBrush *pBrush;
CBrush brLogBrush;
LOGBRUSH LogBrush;

LogBrush.lbStyle = BS_HATCHED;
LogBrush.lbColor = RGB(255, 0, 255);
LogBrush.lbHatch = HS_DIAGCROSS;

brLogBrush.CreateBrushIndirect(&LogBrush);
pBrush = pDC->SelectObject(&brLogBrush);

pDC->Rectangle(20, 12, 250, 175);

pDC->SelectObject(pBrush);
}
Free download pdf