Microsoft KB Archive/183161

= BUG: WebBrowser in MFC Does Not Repaint After showModalDialog =

Article ID: 183161

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 4.0 128-Bit Edition
 * Microsoft Internet Explorer 4.01 Service Pack 2

-



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:

 Create an MFC application that hosts the WebBrowser control.  Using your MFC application, navigate to a Web page that calls the showModalDialog function. Here is an example of how this is done:  Sub Btn_onClick showModalDialog "test.htm" End Sub 

Open a New Window  Close the modal dialog box.</li></ol>

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; }

<div class="references_section">