The final requirement is to set CircleOffset to 0 whenever the size of the control changes. This can be done by adding a notification function, OnSize
, to CCircCtrl
that responds to a WM_SIZE message.
To add the OnSize function
The New Windows Message and Event Handlers dialog box is displayed.
This returns you to the CIRCCTL.CPP file with the insertion point positioned at the code for the OnSize
member function. Add the code shown below.
The OnSize
member function resets the CircleOffset property to 0 only if CircleShape is TRUE. This ensures that the circle always stays within the bounding rectangle of the control no matter how the control is resized. Setting the CircleOffset property to 0 is the simplest way to accomplish this task.
void CCircCtrl::OnSize(UINT nType, int cx, int cy)
{
COleControl::OnSize(nType, cx, cy);
// If circle shape is true, reset the offset when control size is changed
if (m_circleShape)
SetCircleOffset(0);
}