Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


// Bottom Triangle
Pt[0] = CPoint( 95, 155);
Pt[1] = CPoint(125, 215);
Pt[2] = CPoint(155, 155);

pBrush = pDC->SelectObject(&BrushYellow);
pDC->Polygon(Pt, 3);

// Right Triangle
Pt[0] = CPoint(170, 80);
Pt[1] = CPoint(170, 140);
Pt[2] = CPoint(230, 110);

pBrush = pDC->SelectObject(&BrushBlue);
pDC->Polygon(Pt, 3);

pDC->SelectObject(pBrush);
}

If you had declared a CBrush variable using the default constructor, you can initialize it
with a color by calling the CBrush::CreateSolidBrush() method. Its syntax is:

BOOL CreateSolidBrush(COLORREF crColor);

This member function can be used in place of the second constructor. It takes the same
type of argument, a color as crColor and produces the same result. Here is an example:

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

CBrush BrushOlive;
CBrush *pBrush;
Free download pdf