#include "stdafx.h" #include <stdio.h> #include <wchar.h> #include <windows.h> #include <exdisp.h> #include <string> #pragma warning(disable: 4192) #pragma warning(disable: 4146) #import <mshtml.tlb> #import <shdocvw.dll> //using namespace std; void PrintBrowserInfo(IWebBrowser2 *pBrowser) { BSTR bstr; IDispatchPtr spDisp; if (pBrowser->get_Document(&spDisp) == S_OK && spDisp != NULL) { MSHTML::IHTMLDocument2Ptr spHtmlDocument(spDisp); if (spHtmlDocument != NULL) { MSHTML::IHTMLElementPtr spHtmlElement; spHtmlDocument->get_body(&spHtmlElement); } spDisp.Release(); } pBrowser->get_LocationURL(&bstr); wprintf(L" URL: %s\n\n", bstr); ///////////////////////////////// std::wstring wsURL; wsURL = bstr; size_t DSlashLoc = wsURL.find(L"//www."); if (DSlashLoc >= 0) { wsURL.erase(wsURL.begin(), wsURL.begin() + DSlashLoc + 6); } DSlashLoc = wsURL.find(L"/"); if (DSlashLoc != wsURL.npos) wsURL.erase(DSlashLoc); wprintf(L" URL: %s\n\n", wsURL.c_str()); /////////////////////////////////// SysFreeString(bstr); } int urlmain() { 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; }
exdisp.h
PrintBrowserInfo
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)