FIX: WebBrowser Control in CFormView Does Not Repaint Properly

ID: Q179421

The information in this article applies to:

SYMPTOMS

When you resize the WebBrowser control inside a CFormView, it may not repaint correctly.

You may experience the scroll bars not being redrawn.

CAUSE

The WebBrowser control does not handle WM_PAINT messages correctly when it is being resized.

RESOLUTION

When the WebBrowser control is resized, update the client area of the WebBrowser control by calling UpdateWindow().

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been corrected in Microsoft Internet Explorer 4.0.

MORE INFORMATION

The following code shows how the WebBrowser control would normally be resized when the client window is resized. The call to UpdateWindow() causes a WM_PAINT message to be sent directly to the window of the control.

   // CMyFormView is derived from CFormView.
   // m_browser is a CWnd-derived class that wraps the webbrowser control.
   void CMyFormView::OnSize(UINT nType, int cx, int cy)
   {
      CFormView::OnSize(nType, cx, cy);
      // Ensure m_browser has valid HWND before doing anything
      if ( m_browser.GetSafeHwnd() )
      {
         // Resize WebBrowser control to fill the client area
         m_browser.MoveWindow(0, 0, cx, cy);
         // Force processing of WM_PAINT
         m_browser.UpdateWindow();
      }
   }

Additional query words: web browser shdocvw.dll
Keywords          : AXSDKWebBrowser 
Version           : WINDOWS:1.0,3.0,3.01,3.02; WINNT:4.2,4.2b,5.0
Platform          : WINDOWS winnt
Issue type        : kbbug
Solution Type     : kbfix

Last Reviewed: June 23, 1998