CBrush myBrush(RGB(255, 0, 0)); // creates a red brush pDC->SelectObject(&myBrush); // selects the brush for drawing pDC->Rectangle(10, 10, 100, 100); // fills a rectangle with the red brush
CBrush myBrush(HS_CROSS, RGB(0, 0, 255)); // creates a blue crosshatch brush pDC->SelectObject(&myBrush); // selects the brush for drawing pDC->Ellipse(10, 10, 100, 100); // fills an ellipse with the blue crosshatch brushIn both examples, the brush is created using the CBrush constructor, and then selected into the device context (pDC) using the SelectObject function before drawing the shape. The first example creates a solid color brush using the RGB macro, while the second example creates a hatch brush using the HS_CROSS style and a blue color. Package Library: Microsoft Foundation Class (MFC) library.