Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 7: GDI Accessories and Tools Visual C++ and MFC Fundamentals


As seen on the figure and the formula, a rectangle spans from coordinates (x1, y1) to (x2,
y2). Here is an example:

void CExoView::OnDraw(CDC* pDC)
{
pDC->Rectangle(20, 20, 226, 144);
}

When drawing a rectangle, if the value of x2 is less than that of x1, then the x2 coordinate
would mark the left beginning of the figure. This scenario would also apply if the y2
coordinate were lower than y1.

To draw a rectangle, you can also use a RECT or a CRect object. The syntax you would
use is:

BOOL Rectangle(LPCRECT lpRect);

In this case, you must have defined a RECT or a CRect value and pass it as a pointer to
the Rectangle() method. Here is an example:

void CExoView::OnDraw(CDC* pDC)
{
CRect Recto(328, 125, 48, 25);
pDC->Rectangle(&Recto);
}
Free download pdf