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
The Add Member Function dialog box is displayed.
void
. This is the type of value the function will return.GetDrawRect(CRect* rc)
. 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;
}
}
}