Centralize the Sending of Update Hints

There are several occasions when Container needs to send the HINT_UPDATE_ITEM hint for a CContainerItem object, for example, when the object is selected, deselected, resized, or otherwise changed. The HINT_UPDATE_ITEM hint must be passed to OnUpdate in conjunction with the CObject* pHint parameter, which is a pointer to CContainerItem. Thus, it makes sense to have the CContainerItem object itself send the update hint by using the document’s UpdateAllViews function. CContainerItem::InvalidateItem is a helper function that you can call whenever you want to send the hint.

To centralize the sending of update hints in the CContainerItem object

  1. In ClassView, right-click the class CContainerItem.

  2. From the pop-up menu, click Add Member Function.

  3. Fill in the Add Member Function dialog box as follows:
  4. To implement CContainerItem::InvalidateItem, type the following code inside the handler:
    GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_ITEM, this);
    

    Note that the framework keeps track of which document object owns the CContainerItem object and therefore implements CContainerItem::GetDocument.