Microsoft KB Archive/137139

= How To Optimize the Reactivation of In-Place Active Servers =

Article ID: 137139

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.51

 Microsoft Visual C++ 1.52 Professional Edition

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 2.2</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q137139

<div class="summary_section">

SUMMARY
When an OLE container embeds an in-place active capable server, the deactivation/reactivation process may be considered too long. One way to optimize the process is to hide the server rather than deactivate it. Simply hiding the server will enable a faster reactivation should the embedded object be reactivated.

<div class="moreinformation_section">

MORE INFORMATION
Optimizing the deactivation/reactivation process for an object embedded in an MFC container application involves overriding the virtual COleClientItem::OnDeactivateUI and COleClientItem::OnActivate methods.

By default, MFC OLE container applications created with versions of AppWizard prior to version 4.0 contain the following implementation of the COleClientItem::OnDeactivateUI method: 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.

Beginning with Visual C++ version 4.0, AppWizard-generated OLE containers contain the optimized versions of COleClientItem::OnDeactivateUI and COleClientItem::OnActivate automatically. There is no need to manually add the changes shown above.

Additional query words: Word embedded UIActive

Keywords: kbhowto kbinplaceact KB137139

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.