BUG: WebBrowser in MFC Does Not Repaint After showModalDialog (183161)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01

This article was previously published under Q183161

SYMPTOMS

The WebBrowser control hosted in an MFC application does not repaint properly after the DHTML showModalDialog() function is called by the displayed page and the dialog box is closed. Other dialog boxes such as Alerts do not cause this problem.

After the dialog box is closed, a white patch, which is the size of the dialog box, remains.

CAUSE

The WebBrowser control does not handle the WM_ERASEBKGND message correctly in this case.

RESOLUTION

Handle the WM_ERASEGKGND message in your CView-derived class. Return from the OnEraseBkgnd() method without calling the base class OnEraseBkgnd().

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

To reproduce this behavior, follow these steps:

  1. Create an MFC application that hosts the WebBrowser control.
  2. Using your MFC application, navigate to a Web page that calls the showModalDialog() function. Here is an example of how this is done:
    <SCRIPT LANGUAGE="VBScript">
       Sub Btn_onClick
          showModalDialog "test.htm"
       End Sub
    </SCRIPT>
    
    <BUTTON ID="Btn">Open a New Window</BUTTON>
    						
  3. Close the modal dialog box.
After closing the dialog box, a white patch remains where the dialog box once was displayed. You can remove this white patch by performing an action that causes the client area to be repainted, such as minimizing and restoring the application.

When MFC hosts a control, it subclasses that control and passes certain messages to the control. This is the case for the WM_ERASEBKGND message.

When you close the dialog box that was created with showModalDialog(), MFC calls the windows procedure of the WebBrowser control and passes the WM_ERASEBKGND message. In this case, the WebBrowser control does not repaint itself.

In order to stop this problem from happening, you must prevent this message from being sent to the WebBrowser control. To do this, just handle the WM_ERASEBKGND message in your CView-derived class. Then, in your message handler, return without calling the base class version of the handler function.

Here is the MFC code that demonstrates how this should be done:
BOOL CWBView::OnEraseBkgnd(CDC* pDC)
{
   return FALSE;
}
				

REFERENCES

For more information about the WM_ERASEBKGND message and the OnEraseBkgnd method, please refer to the Visual C++ 5.0 documentation.
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

Modification Type:MajorLast Reviewed:5/11/2006
Keywords:kbbug kbpending KB183161