Adding the OnSize Function

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

  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 Windows Message Handler.

    The New Windows Message and Event Handlers dialog box is displayed.

  3. In the New Windows messages/events list box, select WM_SIZE.

  4. Click Add and Edit.

    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);
}