3,245
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include <iostream>
#import <shdocvw.dll>
#include "shlwapi.h"
#include <mshtml.h>
#import <mshtml.tlb>
#include <string>
using namespace std;
int main(){
CoInitialize(0);
SHDocVw::IShellWindowsPtr m_spSHWinds;
if (m_spSHWinds == NULL){
if (m_spSHWinds.CreateInstance(__uuidof(SHDocVw::ShellWindows)) != S_OK){
CoUninitialize();
}
}
if (m_spSHWinds){
int n = m_spSHWinds->GetCount();
for (int i = 0; i < n; i++){
//_variant_t v = (long)i;
_variant_t v(long(i), VT_I4);
IDispatchPtr spDisp = m_spSHWinds->Item(v);
SHDocVw::IWebBrowser2Ptr spBrowser(spDisp); //生成一个IE窗口的智能指针
if (spBrowser){
_bstr_t bsName;
bsName = spBrowser->GetLocationURL(); //中断
spBrowser->AddRef();
void * pData = spBrowser;
string s=bsName;
cout<<s<<endl;
if(s=="http://www.baidu.com/"){
IDispatchPtr p=spBrowser->GetDocument();
MSHTML::IHTMLDocument2Ptr d;
p.QueryInterface(IID_IHTMLDocument2,&d);
MSHTML::IHTMLElementPtr e;
d->get_body(&e);
BSTR text;
e->get_innerHTML(&text);
char *s=_com_util::ConvertBSTRToString(text);
cout<<s<<endl;
}
}
}
}
CoUninitialize();
return 0;
}