CDC::Rectangle
This method draws a rectangle using the current pen. The interior of the rectangle is filled using the current brush.
BOOL Rectangle(
int x1,
int y1,
int x2,
int y2 );
BOOL Rectangle(
LPCRECT lpRect );
Parameters
- x1
The x-coordinate of the upper-left corner of the rectangle, in logical units. - y1
The y-coordinate of the upper-left corner of the rectangle, in logical units. - x2
The x-coordinate of the lower-right corner of the rectangle, in logical units. - y2
The y-coordinate of the lower-right corner of the rectangle, in logical units. - lpRect
The rectangle in logical units. You can pass a CRect object or a pointer to a RECT structure for this parameter.
Return Value
Nonzero if the function is successful; otherwise, it is zero.
Remarks
The rectangle extends 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.
Example
void CMyView::OnDraw(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 the client rectangle. CRect rect; GetClientRect(rect); // Shrink the rectangle 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); }
Requirements
** Windows CE versions:** 1.0 and later
Header file: Declared in Afxwin.h
Platform: H/PC Pro, Palm-size PC, Pocket PC