Help and Support
 

powered byLive Search

BUG: DocumentComplete Does Not Fire When WebBrowser Is Not Visible

Article ID:259935
Last Review:May 12, 2003
Revision:2.0
This article was previously published under Q259935
On This Page

SYMPTOMS

When its Visible property is set to "False", the WebBrowser control (Shdocvw.dll) does not fire the DocumentComplete event and a document does not reach READYSTATE_COMPLETE state.

Back to the top

RESOLUTION

The best workaround for applications that rely on a hidden WebBrowser control is for you to position the control so that it draws its user interface off its container window. To do this, set the Left property of the control equal to the negative of its Width property. In multimonitor scenarios, negative values can be valid screen coordinates, so the Left property value must be set to coordinates that are outside the values returned by calling the EnumDisplayMonitors() method.

Alternately, if the WebBrowser user interface is not needed, the WinInet APIs can provide much of the same functionality.

Back to the top

STATUS

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

Back to the top

MORE INFORMATION

Steps to Reproduce Behavior

1.Start a new Standard EXE project in Visual Basic. Form1 is created by default.
2.Add the Microsoft Internet Controls (Shdocvw.dll) to the project. To so, from the Project menu, click Components.
3.Add the following controls to Form1:
   Object                     Name                  Caption
   -------------------------------------------------------------------

   WebBrowser                 WebBrowser1            
   CheckBox                   chkVisible            Visible (value of 1 - checked)
   CommandButton              cmdNavigate           Navigate
   CommandButton              cmdReadyState         ReadyState

 
					
4.Copy the following code into the Code window of Form1:
   Private Sub cmdNavigate_Click()
      WebBrowser1.Navigate2 "http://msdn.microsoft.com/workshop"
   End Sub

   Private Sub cmdReadyState_Click()
      MsgBox WebBrowser1.Document.ReadyState
   End Sub

   Private Sub chkVisible_Click()
      WebBrowser1.Visible = chkVisible.Value
   End Sub

   Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object,
                                            URL As Variant)
      MsgBox "DocumentComplete!"
   End Sub

   Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object,
                                             URL As Variant)
      MsgBox "NavigateComplete2!"
   End Sub
					
5.From the Run menu, click Start or press the F5 key to start the program.
6.Click the Navigate button. Notice that both the NavigateComplete2 and DocumentComplete events are fired.
7.Clear the Visible checkbox to hide the WebBrowser control. Click the Navigate button again. Notice that only the NavigateComplete2 event is fired. Using the ReadyState button, verify that the control's ReadyState has not reached READYSTATE_COMPLETE (4).

When you click Navigate again, the same behavior occurs. The DocumentComplete event is only fired when the Visible checkbox is selected, making the WebBrowser control visible again. You can correct the behavior by replacing the chkVisible_Click handler with the following code:
   Private Sub chkVisible_Click()
       If chkVisible.Value Then
           WebBrowser1.Left = 120 ' or whatever the normal Left value is
       Else
           WebBrowser1.Left = -WebBrowser1.Width
       End If
   End Sub
					

Back to the top

REFERENCES

For additional information, please see the following MSDN Web Workshop sites:

DocumentComplete Event
http://msdn.microsoft.com/workshop/browser/webbrowser/reference/events/DocumentComplete.asp (http://msdn.microsoft.com/workshop/browser/webbrowser/reference/events/DocumentComplete.asp)

Microsoft Win32 Internet Functions Reference
http://msdn.microsoft.com/workshop/networking/wininet/reference/reference.asp (http://msdn.microsoft.com/workshop/networking/wininet/reference/reference.asp)

Back to the top


APPLIES TO
Microsoft Internet Explorer 4.0 128-Bit Edition
Microsoft Internet Explorer 4.01 Service Pack 2
Microsoft Internet Explorer 4.01 Service Pack 1
Microsoft Internet Explorer 5.0
Microsoft Internet Explorer 5.01
Microsoft Internet Explorer 5.5

Back to the top

Keywords: 
kbbug kbwebbrowser KB259935

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.