The GetDrawRect Function

The GetDrawRect function determines the coordinates of the bounding rectangle in which the ellipse should be drawn. If the CircleShape property is TRUE, GetDrawRect calculates the coordinates of the square region centered in the rectangle rc, which was passed to GetDrawRect. The coordinates of the square region are put back into rc. If CircleShape is FALSE, the function leaves rc untouched.

To add the GetDrawRect function

  1. On WizardBar, select CCircCtl to edit the CCIRCCTL.CPP file.

  2. Click the arrow on the action button, located on the right end of WizardBar, and select Add Member Function.

    The Add Member Function dialog box is displayed.

  3. In the Function Type edit box, type void. This is the type of value the function will return.

  4. In the Function Declaration edit box, type GetDrawRect(CRect* rc).

  5. Under Access, click Protected.

  6. Click OK to close the Add Member Function dialog box.

This will add the following declaration in the protected section of CIRCCTL.H:

void GetDrawRect(CRect* rc);

It will also add the following function definition at the end of CIRCCTL.CPP and position the insertion point in the function:

void CCircCtrl::GetDrawRect(CRect* rc)
{

}

Add code to the function in CIRCCTL.CPP as shown below:

void CCircCtrl::GetDrawRect(CRect* rc)
{
    if (m_circleShape)
    {
        int cx = rc->right - rc->left;
        int cy = rc->bottom - rc->top;

        if (cx > cy)
        {
            rc->left += (cx - cy) / 2;
            rc->right = rc->left + cy;
        }
        else
        {
            rc->top += (cy - cx) / 2;
            rc->bottom = rc->top + cx;
        }
    }
}