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