Rubber-Banding and Trackers
Another feature supplied with trackers is the "rubber-band" selection, which allows a user to select multiple OLE items by dragging a sizing rectangle around the items to be selected. When the user releases the left mouse button, items within the region selected by the user are selected and can be manipulated by the user. For instance, the user might drag the selection into another container application.
Implementing this feature requires some additional code in your application's WM_LBUTTONDOWN handler function.
The following code sample implements rubber-band selection and additional features.
else if (m_Tracker.HitTest(point) < 0)
{
// just to demonstrate CRectTracker::TrackRubberBand
CRectTracker trackerRubber;
if (trackerRubber.TrackRubberBand(this, point, TRUE))
{
MessageBeep(0); // beep indicates TRUE
// See if rubber band intersects
// with the doc's tracker
CRect rectT;
// so intersect rect works
trackerRubber.m_rect.NormalizeRect();
if (rectT.IntersectRect(trackerRubber.m_rect, m_Tracker.m_rect))
{
// If so, put resize handles on it (i.e. select it)
if (m_Tracker.m_nStyle & CRectTracker::resizeInside)
{
// swap from resize inside to resize outside for effect
m_Tracker.m_nStyle &= ~CRectTracker::resizeInside;
m_Tracker.m_nStyle |= CRectTracker::resizeOutside;
}
else
{
// Just use inside resize handles on first time
m_Tracker.m_nStyle &= ~CRectTracker::resizeOutside;
m_Tracker.m_nStyle |= CRectTracker::resizeInside;
}
GetDocument()->SetModifiedFlag();
GetDocument()->UpdateAllViews(NULL);
}
}
}
If you want to allow reversible orientation of the tracker during rubber-banding, you should call CRectTracker::TrackRubberBand with the third parameter set to TRUE. Remember that allowing reversible orientation will sometimes cause CRectTracker::m_rect to become inverted. This can be corrected by a call to CRect::NormalizeRect.
For more information, see Container Client Items and Customizing Drag and Drop.