Article ID: 137139
Article Last Modified on 11/21/2006
void CCntrItem::OnDeactivateUI(BOOL bUndoable)
{
COleClientItem::OnDeactivateUI(bUndoable);
// Close an in-place active item whenever it removes the user
// interface. The action here should match as closely as possible
// the handling of the ESC key in the view.
Deactivate(); // nothing fancy here -- just deactivate the object
}
To optimize the deactivation/reactivation process, modify the AppWizard
generated version of this function to have it invoke the embedded item's
OLEIVERB_HIDE verb to have the item hide itself:
void CCntrItem::OnDeactivateUI(BOOL bUndoable)
{
COleClientItem::OnDeactivateUI(bUndoable);
// Hide the object if it is not an outside-in object
DWORD dwMisc = 0;
m_lpObject->GetMiscStatus(GetDrawAspect(), &dwMisc);
if (dwMisc & OLEMISC_INSIDEOUT)
DoVerb(OLEIVERB_HIDE, NULL);
}
The second step in optimizing the deactivation/reactivation process
involves modifying the virtual COleClientItem::OnActivate method to
correctly handle activation of another embedded object. To override
COleClientItem::OnActivate, first add the following public method
declaration to the declaration of the MFC container application's
COleClientItem derived class:
virtual void OnActivate();Add the following definition of the OnActivate method to the implementation file for the container's COleClientItem derived class:
void CCntrItem::OnActivate()
{
// allow only one in-place active item per frame
CView* pView = (CView*)GetActiveView();
ASSERT_VALID(pView);
COleClientItem* pItem = GetDocument()->GetInPlaceActiveItem(pView);
if (pItem != NULL && pItem != this)
pItem->Close();
COleClientItem::OnActivate();
}
If the container has previously hidden an embedded object, this function
will close it prior to activating the new item. Note that this optimization
is similar to the technique that Microsoft Excel and the rich edit control
use in similar circumstances.Additional query words: Word embedded UIActive
Keywords: kbhowto kbinplaceact KB137139