Connecting to Running Instances of Internet Explorer
Environment: Internet Explorer 4 (and above)
After a little research, I came across a shell interface that would do the trick. It turns out that this is how the shell keeps track of all the shell browsers (both Windows Explorer and Internet Explorer instances!).
Not only does the shell keep track of all Explorer instances, it also notifies when a new Explorer instance is created or deleted.
When you enumerate these Explorer instances, you can query whether as to whether the entry supports the IWebBrowser interface. If it does, it could either be a WebBrowser or a ShellBrowser. Once you obtain the IWebBrowser2 interface, you can either use that interface to manipulate (and communicate with) the Explorer instance or you can trap its events using the DWebBrowserEvents.
Before you get started, you'll need to include the following two lines somewhere in your project:
#import "mshtml.tlb" <span class="codeComment">// Internet Explorer 5</span>
Now, simply use the following code to connect to a Web browser instance
if(m_spSHWinds == 0)
<span class="codeComment">// Get reference to ShellWindows interface</span>
if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK)
<span class="codeComment">// Event Sink </span>
if ((m_spSHWinds != NULL) &&
ASSERT(pConnPtCont != NULL);
LPCONNECTIONPOINT pConnPt = NULL;
DWORD dwCookie = 0;
ASSERT(pConnPt != NULL);
pConnPt->Advise( this->GetIDispatch(FALSE), &dwCookie);
AfxMessageBox("Shell Windows interface is not avilable");
DownloadsDownload source - 15 Kb