#include <windows.h>
#include <stdlib.h>
#pragma warning(disable : 4192)
#import <mshtml.tlb>
#import <shdocvw.dll>
int main()
{
CoInitialize(NULL);
SHDocVw::IShellWindowsPtr pShellWindows;
IDispatchPtr pDisp;
HRESULT hr = pShellWindows.CreateInstance(__uuidof(SHDocVw::ShellWindows));
if (SUCCEEDED(hr))
{
long nCount = pShellWindows->GetCount();
for (long i = 0; i < nCount; ++i)
{
_variant_t va(i, VT_I4);
pDisp = pShellWindows->Item(va);
SHDocVw::IWebBrowser2Ptr pBrowser(pDisp);
if (pBrowser != NULL)
{
_bstr_t str = pBrowser->GetLocationName();
wprintf_s(L"%d. %s\n", i, (LPCWSTR)str);
SysFreeString(str);
pBrowser = NULL;
}
pDisp = NULL;
}
}
pShellWindows = NULL;
CoUninitialize();
return 0;
}
I needed this program few days ago but made it only today.
More info in MSDN:
ShellWindows Object
InternetExplorer Object
No comments:
Post a Comment