Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


BrushOlive.CreateSolidBrush(RGB(255, 2, 5));
pBrush = pDC->SelectObject(&BrushOlive);

pDC->Ellipse(20, 20, 226, 144);
pDC->SelectObject(pBrush);
}

7.6.3 Hatched Brushes..................................................................................


A hatch brush is one that uses a drawn pattern to regularly fill an area. Microsoft
Windows provides 6 preset patterns for such a brush. To create a hatched brush, you can
use the following constructor:

CBrush(int nIndex, COLORREF crColor);

If you had declared a CBrush variable using the default constructor, you can call the
CreateHatchBrush() member function to initialize it. The syntax of this method is:

BOOL CreateHatchBrush(int nIndex, COLORREF crColor);

In both cases, the nIndex argument specifies the hatch pattern that must be used to fill the
area. The possible values to use are HS_BDIAGONAL, HS_CROSS, HS_DIAGCROSS,
HS_FDIAGONAL, HS_HORIZONTAL, or HS_VERTICAL.
The crColor argument specifies the color applied on the drawn pattern.
Here is an example:
void CExoView::OnDraw(CDC* pDC)
{
CExoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);

CBrush brBDiagonal(HS_BDIAGONAL, RGB(0, 0, 255));
CBrush brCross;
CBrush brDiagCross(HS_DIAGCROSS, RGB(0, 128, 0));
CBrush brFDiagonal;
CBrush brHorizontal(HS_HORIZONTAL, RGB(255, 128, 0));
CBrush brVertical;

CBrush *pBrush;
Free download pdf