Modifying OnDraw

The GetDrawRect function greatly simplifies the changes that need to be made to the OnDraw function. The modifications to OnDraw introduce a local CRect object, rc, whose value is initialized to the value of rcBounds. Before the ellipse is drawn, GetDrawRect is called. If the value of the CircleShape property is TRUE, GetDrawRect adjusts the coordinates in rc to be the square region centered within rcBounds.

Add the following individual lines of code to CIRCCTL.CPP:

    CRect rc = rcBounds;
    GetDrawRect(&rc);

and modify the following line of code:

    pdc->Ellipse(rcBounds);

to match what is shown in the following code example:

void CCircCtrl::OnDraw(
            CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
    CBrush* pOldBrush;
    CBrush bkBrush(TranslateColor(GetBackColor()));
    CPen* pOldPen;
    CRect rc = rcBounds;

    // Paint the background using the BackColor property
    pdc->FillRect(rcBounds, &bkBrush);

    // Draw the ellipse using the BackColor property and a black pen
    GetDrawRect(&rc);
    pOldBrush = pdc->SelectObject(&bkBrush);
    pOldPen = (CPen*)pdc->SelectStockObject(BLACK_PEN);
    pdc->Ellipse(rc);
    pdc->SelectObject(pOldPen);
    pdc->SelectObject(pOldBrush);
}