Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Problem - Launch a TAB in existing instance of IE and then obtain IWebBrowser2 ptr to this TAB
User - to Provide 'title' of the target page

Which of these is the fastest & reliable?

Code for launching TAB is not included here

Method 1 -

Using IShellWindow, get count of all windows and also obtain pIDispatch using Item() call 
For every shell window
    pIDispatch->QueryInterface (IID_IWebBrowser2,&pBrowser);
    pBrowser->get_HWND(&hwnd)
    // GetClassName & go ahead only for 'IEFrame' class
    // Wait for ready state - the most time consuming 
    pBrowser->get_Document (&pIDispDoc);
    // get HTML document title
    pIDispDoc->QueryInterface(IID_IHTMLDocument2,(void**)&pIHTMLDoc);
    pIHTMLDoc->get_title(&bstr)
    // compare title with expected title


Method 2 -
Using EnumWindows() go only for 'IEFrame' class
    for each 'IEFrame' use EnumChildWindow() and get 'Internet Explorer_Server' 
         finally for each 'Internet Explorer_Server'  get the window handle
         using this handle get title text 
            If this title matches expected title
                Pass 'WM_HTML_GETOBJECT' to get the IWebBrowser2


Method 3 -
Using IShellWindow get cnt of all windows and also obtain pIDispatch using Item() call 
For every shell window
    pIDispatch->QueryInterface (IID_IWebBrowser2,&pBrowser);
    pBrowser->get_HWND(&hwnd)
    // GetClassName & go ahead only for 'IEFrame' class
    (IWebBrowser2 ==> QueryInterface for IServiceProvider,
    IServiceProvider ==>QueryService for IOleWindow, IOleWindow ==> GetWindow)
    From window get the title 
    // compare title with expected title


Method 4 -

Monitor the 'NewProcess' for TAB creation using EventSink
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900