Receive the Hint and Invalidate the View

The framework provides a mechanism for invalidating portions of a view by using the lHint and pHint parameters of CView::OnUpdate. This “update hint” mechanism is described in the Scribble tutorial and is used in Container.

To receive the hint and invalidate the view

  1. On the View menu, click ClassWizard.

  2. Click the Message Maps tab.

  3. In the Class name drop-down list box, select CContainerView.

  4. In the Messages list box, select OnUpdate, and click Add Function. This adds the OnUpdate function declaration to CContainerView.h and a starter function definition to CContainerView.cpp.

  5. Click Edit code to jump to the function definition in CContainerView.cpp.

  6. Implement OnUpdate by replacing the //TODO comment with the following code:
    switch (lHint)
    {
    case HINT_UPDATE_WINDOW:    // invalidate entire window
    Invalidate();
    break;
    case HINT_UPDATE_ITEM:        // invalidate single item
    {
    CRectTracker tracker;
    SetupTracker((CContainerItem*)pHint, &tracker);
    CRect rect;
    tracker.GetTrueRect(rect);
    InvalidateRect(rect);
    }
    break;
    }
    

    The rectangle to be invalidated for HINT_UPDATE_ITEM should include the area that might be occupied by a tracker around the object. The implementation of CContainerView::OnUpdate takes this into account.