Ok, you need a whole new approach. Easiest way would be with shell connectors as described at
http://www.codeguru.com/Cpp/I-N/ieprogram/article.php/c4403[
^]. This works with IE versions 5 - 10 (version 10 is pre-release with windows 8).
This code is the relevant parts of that article in a minimal console program.
Basic idea is attach to the shell windows enumerator and go through the list of windows. This is done in the
main()
function.
It then prints some details on each window found in the
PrintBrowserInfo()
function.
#include <stdio.h>
#include <wchar.h>
#include <Windows.h>
#include <Exdisp.h>
#pragma warning(disable: 4192)
#pragma warning(disable: 4146)
#import <mshtml.tlb>
#import <shdocvw.dll>
void PrintBrowserInfo(IWebBrowser2 *pBrowser) {
BSTR bstr;
pBrowser->get_LocationName(&bstr);
wprintf(L"Title: %s\n", bstr);
SysFreeString(bstr);
IDispatchPtr spDisp;
char *type = "Windows Explorer";
if (pBrowser->get_Document(&spDisp) == S_OK && spDisp != NULL) {
MSHTML::IHTMLDocument2Ptr spHtmlDocument(spDisp);
if (spHtmlDocument != NULL) {
MSHTML::IHTMLElementPtr spHtmlElement;
spHtmlDocument->get_body(&spHtmlElement);
if (spHtmlElement != NULL) {
type = "Internet Explorer";
}
}
spDisp.Release();
}
printf(" Type: %s\n", type);
pBrowser->get_LocationURL(&bstr);
wprintf(L" URL: %s\n\n", bstr);
SysFreeString(bstr);
}
int main() {
CoInitialize(NULL); SHDocVw::IShellWindowsPtr spSHWinds;
IDispatchPtr spDisp;
if (spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) == S_OK) {
long nCount = spSHWinds->GetCount();
for (long i = 0; i < nCount; i++) {
_variant_t va(i, VT_I4);
spDisp = spSHWinds->Item(va);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp);
if (spBrowser != NULL) {
PrintBrowserInfo((IWebBrowser2 *)spBrowser.GetInterfacePtr());
spBrowser.Release();
}
}
} else {
puts("Shell windows failed to initialise");
}
system("PAUSE");
return 0;
}