Connecting to Running Instances of Internet Explorer | CodeGuru

Connecting to Running Instances of Internet Explorer

There has been always a problem connecting to web browsers, Either you need to write Browser Helper Object or something which browser needs to instantiate. But I found all the other methods had one or other way bug in it. Decided to find simple and bug free way, And came across this ShellWindows interface, which […]

Written By
CodeGuru Staff
CodeGuru Staff
Jan 16, 2001
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

There has been always a problem connecting to web browsers,
Either you need to write Browser Helper Object or something which browser needs to instantiate.
But I found all the other methods had one or other way bug in it.
Decided to find simple and bug free way, And came across this ShellWindows interface,
which is used by Shell to keep track all the shell browsers including Shell Folders and Internet explorers
I Believe shell uses name spaces to keep track of this windows.

Not only shell windows keeps track of all shell windows and also notifies when new shell window is created or deleted.

When you enumerate, you can query whether the entry supports IWebBrowser interface,
if it does it could be either WebBrowser or ShellBrowser. Once you get hold of IWebBrowser2 interface,
you can either use it or listen to DWebBrowserEvents or through it away.

Before you start cranking in, you should include

#import "mshtml.tlb": // Internet Explorer 5
#import "shdocvw.dl"

Connecting To web browser using shell windows interface

void CIEEnumWindowsDlg::ConnectToShell()
{
 CoInitialize(NULL);
 if(m_spSHWinds == 0) {
  //
  // Get reference to ShellWindows interface
  //
  if(m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows))
  == S_OK) {
   // Event Sink 
   //
   LPCONNECTIONPOINTCONTAINER pConnPtCont;
   if ((m_spSHWinds != NULL) &&
   SUCCEEDED(m_spSHWinds->QueryInterface(IID_IConnectionPointContainer,
                                         (LPVOID*)&pConnPtCont))) {
    ASSERT(pConnPtCont != NULL);
    LPCONNECTIONPOINT pConnPt = NULL;
    DWORD dwCookie = 0;
    if (SUCCEEDED(pConnPtCont->FindConnectionPoint(
     __uuidof(SHDocVw::DShellWindowsEvents), &pConnPt)))
    {
     ASSERT(pConnPt != NULL);
     pConnPt->Advise( this->GetIDispatch(FALSE), &dwCookie);
     pConnPt->Release();
    }
    pConnPtCont->Release();
   }
  }
  else {
   AfxMessageBox("Shell Windows interface is not avilable");
  }
 }
}

Downloads

Download source - 15 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.