Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

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() 

 if(m_spSHWinds == 0) {
  // Get reference to ShellWindows interface
  == S_OK) {
   // Event Sink 

   if ((m_spSHWinds != NULL) && 
                                         (LPVOID*)&pConnPtCont))) {
    ASSERT(pConnPtCont != NULL);
    DWORD dwCookie = 0;

    if (SUCCEEDED(pConnPtCont->FindConnectionPoint(
     __uuidof(SHDocVw::DShellWindowsEvents), &pConnPt)))
     ASSERT(pConnPt != NULL);
     pConnPt->Advise( this->GetIDispatch(FALSE), &dwCookie);

  else {
   AfxMessageBox("Shell Windows interface is not avilable");


Download source - 15 Kb


  • Need code in c#

    Posted by sharath1984 on 04/15/2011 01:17pm

    Hi, I am having a Web app published in Citrix environment. But when I click on a url it will show a blank IE screen. So can you pls give the above written code in c#.net. Thanks in Advance.

  • Apllication crashes when trying to read URL's in a timer??

    Posted by Legacy on 01/24/2004 08:00am

    Originally posted by: Himanshu

    I am having a problem that applcaition is crashing when i try to list all IE url's in a timer for whole day using a timer. The problem is occurring once in a while and it happens randomly at any place or URL. i.e. suppose my applciation is trying to read a URL and at the same instant user closes IE the browser pointer is still there but it is unable to read URL as the window has been closed. I am also using try catch exception blocks to catch the exception thrown but each time it fails to catch the exception raised and shows abnormal program termination. Is there any way i can read the URL's and can avoid this error. Please help I need to fix this problem. Any help or pointers are highly appreciated. Thanks a lot in advance.Looking forward to a help. Please..

  • crashing problem? abnormal program termination

    Posted by Legacy on 01/06/2004 08:00am

    Originally posted by: Himanshu

    Hi all,

    I am having a problem when i use this to read url's from IE..It terminates itself and shows an abnormal program termination error..I need to sort this problem out..Can someone help me out in doing the same..i need this to be done..Please help me out..any help or poinetrs are thoroughly appreciated...Thanks a lot in advance..

  • DocumentComplete() / NavigateComplete2() technique

    Posted by Legacy on 11/01/2003 08:00am

    Originally posted by: TheFlashback

    A lot of people have complained that DocumentComplete() / NavigateComplete2() do not get fired 
    or get fired too early... Here is the technique that seems to be working properly on XP with IE6:

    // Global...
    LPDISPATCH glpDispatch = NULL;

    BEGIN_DISPATCH_MAP(CIEEnumWindowsDlg, CCmdTarget)
    DISP_FUNCTION_ID(CIEEnumWindowsDlg, "NavigateComplete2",0x000000fc,NavigateComplete2,VT_EMPTY,VTS_DISPATCH VTS_VARIANT)
    DISP_FUNCTION_ID(CIEEnumWindowsDlg, "DocumentComplete",0x00000103,DocumentComplete,VT_EMPTY,VTS_DISPATCH VTS_VARIANT)

    void CIEEnumWindowsDlg::NavigateComplete2(LPDISPATCH lpDispatch,
    if (glpDispatch == 0)
    glpDispatch = lpDispatch;

    void CIEEnumWindowsDlg::DocumentComplete(LPDISPATCH lpDispatch,
    if (glpDispatch == 0 || glpDispatch != lpDispatch)

    CString strOldText;
    strOldText += _T("\r\nDocument is done downloading");

    glpDispatch = NULL;

    IWebBrowser2* pBrowser = 0;
    if (SUCCEEDED(lpDispatch->QueryInterface(IID_IWebBrowser2, (LPVOID*)&pBrowser)))
    BSTR bStrURL;

    strOldText += _T(" URL: ");
    strOldText += CString(bStrURL);


  • URGENT - Calling IE programmatically and Hiding display

    Posted by Legacy on 10/30/2003 08:00am

    Originally posted by: Varun

    Hi All,

    I need to write a program in JAVA which will call IE and open and HTML page in it. But I want that the display of this IE window should not appear before user. Best will be if there will be no sign of opening of IE before user. Second best option is IE appears as a button on taskbar but user is not able to access (restore it to view) it.
    is it possible?

    Pls reply asap.


  • How can I set the proxy to use by connected running instance

    Posted by Legacy on 08/14/2003 07:00am

    Originally posted by: agsapt

    I would like to know if it's possible that once we are connected to a running instance, we can set a proxy to use by that running instance? If that's possible then how?

  • how to fire BeforeNavigate2 event???

    Posted by Legacy on 08/05/2003 07:00am

    Originally posted by: rain

    I want to get a notification when user input a url in address bar or click a link, I think this can be done by capture BeforeNavigate2 event, but I failed to get the notification of this event, what can I do to get the notification? Thanks!

  • Need help -> FileDownload eventhandler not firing

    Posted by Legacy on 07/18/2003 07:00am

    Originally posted by: Dickson

    After connecting to an instance of IE, i'm trying to control/monitor the events. So far everything works but the filedownload event handler. Anybody have any tips on how to do it? The following (C#) is the syntax for all of my event handlers.

    myInternetExplorer.FileDownload += new SHDocVw.DWebBrowserEvents2_FileDownloadEventHandler(OnDownload);

    Any clues/pointers would be helpful! I want to build my own download manager :)


  • how to set URL

    Posted by Legacy on 07/08/2003 07:00am

    Originally posted by: tony

    anyone know how can I use a simple wrapper class/application such at I can from my application tell the instant to visit the url one by one? I don't need to get anything back, just need to visit the links and make sure the links are all working.


  • Possibility to use Navigate ?

    Posted by Legacy on 05/26/2003 07:00am

    Originally posted by: Philippe Legrand


    Glad to have poken around and found this article !!
    BUT :( I am unable to use the .Navigate ou Navigate2 methods on IWebBrowser2 interface :((

    Here is my piece of code, plugged into the sample source code :
    Everything is working smoothly except MY CODE : the navigate call ! :((

    Is there any limitation on the interfaces we got by this way ?? Any idea why Navigate does return -858993460 and leads my program to "unknow error" ??

    Thanks for your help and sorry for code indenting :(


    void CIEEnumWindowsDlg::OnVs()
    // TODO: Add your control notification handler code here
    _bstr_t locationtogo="http://help.yahoo.com/help/us/edit/edit-01.html";;
    VARIANT vURL, vDummy;
    vURL.vt = VT_BSTR;
    vURL.bstrVal = locationtogo.copy();

    int index = m_List.GetCurSel();
    if(index != CB_ERR) {
    IWebBrowser2 *pBrowser = (IWebBrowser2 *)m_List.GetItemDataPtr(index);
    if(pBrowser) {
    AfxMessageBox("Navigate now");
    //int a=pBrowser->Navigate(locationtogo,NULL,NULL,NULL,NULL);
    int a=pBrowser->Navigate(locationtogo, &vDummy, &vDummy, &vDummy, &vDummy);
    if (a!=S_OK) {
    if (a==E_INVALIDARG) AfxMessageBox("Nav failed due to bad args");
    else if (a==E_OUTOFMEMORY) AfxMessageBox("Nav failed out of memory !");
    else AfxMessageBox("unknown error");
    IDispatchPtr spDisp;
    if(pBrowser->get_Document(&spDisp) == S_OK && spDisp!= 0 ) {
    MSHTML::IHTMLDocument2Ptr spHtmlDocument(spDisp);
    MSHTML::IHTMLElementPtr spHtmlElement;
    if(spHtmlElement != 0) {
    BSTR bstr;

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date