CDC::Rectangle
Visual Studio 2012
Draws a rectangle using the current pen.
BOOL Rectangle( int x1, int y1, int x2, int y2 ); BOOL Rectangle( LPCRECT lpRect );
The interior of the rectangle is filled using the current brush.
The rectangle extends up to, but does not include, the right and bottom coordinates. This means that the height of the rectangle is y2 – y1 and the width of the rectangle is x2 – x1. Both the width and the height of a rectangle must be greater than 2 units and less than 32,767 units.
void CDCView::DrawRectangle(CDC* pDC) { // create and select a solid blue brush CBrush brushBlue(RGB(0, 0, 255)); CBrush* pOldBrush = pDC->SelectObject(&brushBlue); // create and select a thick, black pen CPen penBlack; penBlack.CreatePen(PS_SOLID, 3, RGB(0, 0, 0)); CPen* pOldPen = pDC->SelectObject(&penBlack); // get our client rectangle CRect rect; GetClientRect(rect); // shrink our rect 20 pixels in each direction rect.DeflateRect(20, 20); // draw a thick black rectangle filled with blue pDC->Rectangle(rect); // put back the old objects pDC->SelectObject(pOldBrush); pDC->SelectObject(pOldPen); }