BUG: Office Repaint Problem if Modal Form Shown from ActiveX EXE

ID: Q242017


The information in this article applies to:
  • Microsoft Access versions 2000, 97
  • Microsoft Excel 2000
  • Microsoft Outlook 2000
  • Microsoft Word 2000
  • Microsoft Project 98 for Windows
  • Microsoft Excel 97 for Windows
  • Microsoft PowerPoint 97 For Windows
  • Microsoft Word 97 for Windows


SYMPTOMS

When a modal form is displayed from an ActiveX EXE component called from VBA, the 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 this to be a bug in the Microsoft products listed at the beginning of this article.


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 Behavior

  1. Start Visual Basic 6.0, and create a new ActiveX EXE project. Rename the project RepaintTest and rename the public class MyForm.


  2. Add a new Form to the project. Form1 is created by default.


  3. Add a CommandButton to Form1. Inside the event handler for the button's click event, add the following code:


  4. 
    Private Sub Command1_Click()
       Unload Me
    End Sub 
  5. Inside the code module for MyForm, add the following code:


  6. 
    Option Explicit
    
    Public Sub ShowModalForm()
       Dim oModalForm As Form1
       Set oModalForm = New Form1
       
       oModalForm.Show vbModal
       
       Set oModalForm = Nothing
    End Sub 
  7. Choose File|Make <ProjectName> EXE to build and register the ActiveX component.


  8. Open Microsoft Excel and press the ALT+F11 keys to go directly to the VBA Editor.


  9. In the code window for ThisWorkbook, add the following code:


  10. 
    Sub RunTest()
        Dim oActiveXComponent As Object
        Set oActiveXComponent = CreateObject("RepaintTest.MyForm")
        
        oActiveXComponent.ShowModalForm
        
        MsgBox "Did Excel repaint correctly?", vbMsgBoxSetForeground
        
        Set oActiveXComponent = Nothing
    End Sub 
  11. Close the VBA Editor and return to Excel.


  12. 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.


  13. 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.

Additional query words: painting redraw IMessageFilter

Keywords : kbAccess kbActiveX kbAutomation kbExcel kbOutlook kbProject KbVBA kbVBp500 kbVBp600 kbVC kbPowerPt kbWord kbGrpDSO kbExcel97 kbDSupport kbWord97 kbexcel2000 kboutlook2000 kbword2000
Version : WINDOWS:2000,97,98
Platform : WINDOWS
Issue type : kbbug


Last Reviewed: October 1, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.