I need to evaluate the document from each browser window and act accordingly. I’m using shellwindows to obtain the IwebBrowser2. Then I have access to all the document properties I need. ie…
ShellWindows := TshellWindows.Create(nil);
…
ShellWindowDisp := ShellWindows.Item(Count); //for loop
…
ShellWindowDisp.QueryInterface(iWebBrowser2, WebBrowser);
etc….
This method works fine as far as I can tell. However, if one of the documents change my code will never know it. So I need to monitor Explorer for events such as OnDocumentComplete. Dumping the code above into a timer and comparing properties obviously is not the way to go. I’ve found several components that capture events but would rather not rely on a third party component for this. Since my knowledge on this area is limited I need to understand what is going on. Any good articles out there that explain how to approach this, preferably with simple source code?
In order to access the events of the WebBrowser instances, you must get a pointer to the
IConnectionPointContainerinterface using the QueryInterface method of theIWebBrowser2interface, then call the FindConnectionPoint method passing the GUID of the DWebBrowserEvents2 interface and finally call Advise method of theIConnectionPointinterface to start to receive the events.Something like so
All this code must be implemented inside of a class which descends from IDispatch in order to receive the events in the Invoke method. As in your case you need intercept the DocumentComplete event you must check when the value of the DispID parameter is 259.
If you want a sample of this explanation, try checking this code
intercept Internet Explorer messages.