Chapter 8 GDI Orientation and Transformations Visual C++ and MFC Fundamentals
To create a brush based on a bitmap, you can use the following constructor:
CBrush(CBitmap* pBitmap);
If you had declared a CBrush variable using the default constructor, you can call the
CBrush::CreatePatternBrush() member function to initialize it. Its syntax is:
BOOL CreatePatternBrush(CBitmap* pBitmap);
Here is an example:
void CExoView::OnDraw(CDC* pDC)
{
CExoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CBrush brPattern;
CBitmap Bmp;
CBrush *pBrush;
Bmp.LoadBitmap(IDB_BITMAP1);//"C:\\Programs\\woman2.bmp");
brPattern.CreatePatternBrush(&Bmp);
pBrush = pDC->SelectObject(&brPattern);
pDC->Rectangle(46, 46, 386, 386);
pDC->SelectObject(pBrush);
}