Microsoft KB Archive/217391

= PRB: Excel Does Not Repaint Highlighted Cells Correctly in a MFC MDI Active Document Container =

Article ID: 217391

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition  Microsoft Visual C++ .NET 2002 Standard Edition</li> Microsoft Visual C++ .NET 2003 Standard Edition</li></ul>

-

<div class="notice_section">

This article was previously published under Q217391

<div class="symptoms_section">

SYMPTOMS
When an AppWizard-generated MFC MDI Active Document Container has an Excel spreadsheet embedded in one of its views, and another view open at the same time, any highlighted cells in the Excel spreadsheet is not repainted correctly when the other view is dragged over the spreadsheet view.

<div class="cause_section">

CAUSE
This problem occurs because the Excel document server does not "unhighlight" the cells after the document has lost focus. The MFC Active Document Container calls the IOleInPlaceActiveObject::OnDocWindowActivate(FALSE) function from CMDIChildWnd::OnMDIActivate to notify the Active Document Server that it should deactivate the document. The implementation of the Excel document server deactivates the document, but does not unhighlight the cells. Excel unhighlights the cells when its view is redrawn after it has lost focus. Therefore, the Excel document server must be notified to redraw itself after it has lost focus.

<div class="resolution_section">

RESOLUTION
To work around this problem, override CView::OnSetFocus to redraw all views and their embedded servers. To do this, follow these steps: <ol>  Add the following function to the header file of the CView derived class in the protected section: void DoRedraw; </li>  Implement this function as follows in the .cpp file of the CView derived: void CMyAXDocContView::DoRedraw { //  This function causes the embedded Active Document Server to be redrawn // Iterate document templates... POSITION posTmpl = AfxGetApp->GetFirstDocTemplatePosition; while(posTmpl != NULL){ CDocTemplate *pTmpl = AfxGetApp->GetNextDocTemplate(posTmpl); // Iterate documents in this template. POSITION posDoc = pTmpl->GetFirstDocPosition; while(posDoc != NULL) { COleDocument *pDoc = (COleDocument *)pTmpl->GetNextDoc(posDoc);

// Iterate views of each document. POSITION posView = pDoc->GetFirstViewPosition; while(posView != NULL) { CView *pView = pDoc->GetNextView(posView); // Completely redraw. pView->RedrawWindow(NULL, NULL, RDW_ERASE|RDW_INVALIDATE|RDW_UPDATENOW|RDW_FRAME|RDW_ALLCHILDREN); }     }   } }

</li>  Override the OnSetFocus function to call the DoRedraw function in the CView derived class as follows: void CMyAXDocCont1View::OnSetFocus(CWnd* pOldWnd) {   COleClientItem* pActiveItem = GetDocument->GetInPlaceActiveItem(this); if (pActiveItem != NULL &&       pActiveItem->GetItemState == COleClientItem::activeUIState) {       // Need to set focus to this item if it is in the same view. CWnd* pWnd = pActiveItem->GetInPlaceWindow; if (pWnd != NULL) {           pWnd->SetFocus;   // Don't call the base class. DoRedraw;        // Redraw Server return; }   }    DoRedraw;  //  Redraw Server.

CView::OnSetFocus(pOldWnd); }

</li></ol>

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Steps to Reproduce Behavior

 * 1) Generate an MFC MDI Active Document Container in Visual C++ 6.0, or in Visual C++ .NET.
 * 2) On the Build menu, click Run.
 * 3) On the Edit menu, click Insert New Object, and insert a Microsoft Excel Worksheet.
 * 4) On the File menu, click New to open a new view.
 * 5) Highlight some cells in the Excel view.
 * 6) Drag the second view over the highlighted cells and then drag it away.

Notice that the highlighted cells are not repainted.

Keywords: kbactivedocs kbcontainer kbprb KB217391

-

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

© Microsoft Corporation. All rights reserved.