Implementing Tracker Rectangles for Resizing and Moving Objects

When the user moves the cursor over a selected object, the cursor changes its shape to indicate the kind of manipulation available. For example, if the cursor is over the resize handle at the upper-middle or lower-middle side of the tracker rectangle, the cursor changes to a two-way vertical arrow to indicate that the user can drag the upper or lower edge of the object. The framework’s CRectTracker class implements this. All you need to do is call CRectTracker::SetCursor.

To implement special cursors for the tracker

  1. Using WizardBar, select CContainerView from the Class list.

  2. Click the action arrow located on the right end of WizardBar.

  3. Click Add Windows Message Handler.

    The New Windows Message and Event Handlers dialog box appears.

  4. From the New Windows messages/events list box, select WM_SETCURSOR.

  5. Click Add and Edit.

  6. Replace the highlighted //TODO comment with the following code to implement the CContainerView::OnSetCursor handler:

    if (pWnd == this && m_pSelection != NULL)
    {
    // give the tracker for the selection a chance
    CRectTracker tracker;
    SetupTracker(m_pSelection, &tracker);
    if (tracker.SetCursor(this, nHitTest))
    return TRUE;
    }
    

    Note   Your code should come before, but not replace, the call to the base class (CView) that WizardBar adds to the starter handler:

    return CView::OnSetCursor(pWnd, nHitTest, message);