The AppWizard-provided implementation of CContainerView::OnDraw
simply draws the one embedded object pointed to by m_pSelection
. Now that Container supports multiple embedded objects, OnDraw
must be reimplemented accordingly.
To support drawing of multiple embedded objects
OnDraw
function in class CContainerView
. Replace the //TODO comment and the implementation provided by AppWizard with the following code (start after the ASSERT
statement):// draw the OLE items from the list
POSITION pos = pDoc->GetStartPosition();
while (pos != NULL)
{
// draw the item
CContainerItem* pItem = (CContainerItem*)pDoc->GetNextItem(pos);
pItem->Draw(pDC, pItem->m_rect);
// draw the tracker over the item
CRectTracker tracker;
SetupTracker(pItem, &tracker);
tracker.Draw(pDC);
}
Again, a CRectTracker object is used to draw the rectangle and possibly resize handles around the embedded object. The CRectTracker object lives only long enough to draw during this particular repaint. Another CRectTracker object was used, as you saw above, to handle a click on one of the resize handles. Yet another CRectTracker object was used to change the shape of the cursor when it was over one of the resize handles. Each of these CRectTracker objects is short lived; that is, they are automatic (local) variables of the respective Windows event handler. They were all initialized with the common code you added earlier to SetupTracker
.