Microsoft KB Archive/242017

= BUG: Office repaint problem if modal form is shown from ActiveX EXE =

Article ID: 242017

Article Last Modified on 5/11/2007

-

APPLIES TO


 * Microsoft Office Excel 2007
 * Microsoft Office Excel 2003
 * Microsoft Excel 2002 Standard Edition
 * Microsoft Excel 2000 Standard Edition
 * Microsoft Excel 97 Standard Edition
 * Microsoft Office Access 2007
 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition
 * Microsoft Access 2000 Standard Edition
 * Microsoft Access 97 Standard Edition
 * Microsoft Office Outlook 2007
 * Microsoft Office Outlook 2003
 * Microsoft Outlook 2002 Standard Edition
 * Microsoft Outlook 2000 Standard Edition
 * Microsoft Office Word 2007
 * Microsoft Office Word 2003
 * Microsoft Word 2002 Standard Edition
 * Microsoft Word 2000 Standard Edition
 * Microsoft Word 97 Standard Edition
 * Microsoft Project 98 Standard Edition
 * Microsoft PowerPoint 97 Standard Edition

-



This article was previously published under Q242017



SYMPTOMS
When a modal form is displayed from an ActiveX EXE component called from VBA, the Microsoft Office application that made the call does not repaint correctly while the dialog is displayed.



CAUSE
When making an out-going call to an out-of-process COM server, the main thread of the Office application is placed in an RPC thread loop waiting for a response from the server. Because the server is waiting for a modal form to be closed, the main thread of the Office application stops responding. During that time, certain window messages are allowed to pass back to the caller, but due to a limitation with the message filter used by most Office applications, WM_PAINT messages are not getting sent back to the main window for the Office application. The result is that the application does not repaint while the modal form is displayed.

If the dialog is displayed non-modal, the problem does not occur.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.



MORE INFORMATION
To reproduce the behavior you need to build an ActiveX EXE component that displays a modal form. You also need a VBA-enabled Office application. This sample uses Microsoft Visual Basic to build the out-of-process server component, and Microsoft Excel to act as the client. Please note, however, that the problem is not specific to Visual Basic-built components, and is also not limited to Excel.

Steps to reproduce the behavior
 Start Visual Basic 6.0, and create a new ActiveX EXE project. Rename the project RepaintTest and rename the public class MyForm. Add a new Form to the project. Form1 is created by default.  Add a CommandButton to Form1. Inside the event handler for the button's click event, add the following code. Private Sub Command1_Click Unload Me End Sub   Inside the code module for MyForm, add the following code. Option Explicit

Public Sub ShowModalForm Dim oModalForm As Form1 Set oModalForm = New Form1 oModalForm.Show vbModal Set oModalForm = Nothing End Sub  Choose File|Make  EXE to build and register the ActiveX component.</li> Open Microsoft Office Excel and press the ALT+F11 keys to go directly to the VBA Editor.</li>  In the code window for ThisWorkbook, add the following code. Sub RunTest Dim oActiveXComponent As Object Set oActiveXComponent = CreateObject("RepaintTest.MyForm") oActiveXComponent.ShowModalForm MsgBox "Did Excel repaint correctly?", vbMsgBoxSetForeground Set oActiveXComponent = Nothing End Sub

</li> Close the VBA Editor and return to Excel.</li> Press the ALT+F8 keys to bring up the Macros dialog box. Select ThisWorkbook.RunTest and click Run. This creates an instance of your out-of-process component and displays the modal form. Move the form around the screen and you note that Excel does not repaint behind the form.NOTE: Do not switch between applications while running this test. It is possible to get Excel in front of the modal dialog, thereby preventing you from closing the dialog and returning to Excel. If this happens, press the CTRL+ALT+DELETE key combination to bring up the Task Manager. Find RepaintTest.EXE in the Process list and end the task.</li></ol>

Additional query words: painting redraw IMessageFilter ACC2003 ACC2007 XL2003 XL2007 WD2003 WD2007 OL2003 OL2007

Keywords: kbautomation kbbug kbpending KB242017

-

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

© Microsoft Corporation. All rights reserved.