Internet Explorer_Server内容获取
InternetExplorer_Server内容获取使用vc怎么实现呀?我整了好久没弄出来谢谢了...
Internet Explorer_Server内容获取 使用vc怎么实现呀?我整了好久没弄出来
谢谢了 展开
谢谢了 展开
1个回答
展开全部
首先这里假设你已经获取到Internet Explorer_Server窗口的句柄,假设为hwndIE:HWND。
CoInitialize(NULL);
CComPtr<IHTMLDocument2> pDoc2;
string strTemp="";
HINSTANCE hinst=::LoadLibrary("OLEACC.DLL");
if(hinst!=NULL) {
LRESULT lres;
UINT unMsg=::RegisterWindowMessage(_T("WM_HTML_GETOBJECT"));
::SendMessageTimeout(hwndIE,unMsg,0L,0L,SMTO_ABORTIFHUNG,1000,(DWORD*)&lres);
LPFNOBJECTFROMLRESULT pfObjectFromLresult=(LPFNOBJECTFROMLRESULT)::GetProcAddress(hinst,_T("ObjectFromLresult"));
if(pfObjectFromLresult!=NULL) {
HRESULT hres;
hres=(*pfObjectFromLresult)(lres,IID_IHTMLDocument2,0,(void**)&pDoc2);
if(SUCCEEDED(hres)) {
CComPtr<IHTMLElement> pHtmlElem;
hres=pDoc2->get_body(&pHtmlElem);
BSTR bstrText=NULL;
pHtmlElem->get_innerText(&bstrText);
_bstr_t _bstrTemp(bstrText,false);
//strTemp=(char*)_bstr_t(bstrText);
strTemp=(char*)_bstrTemp;
}
}
::FreeLibrary(hinst);
}
CoUninitialize();
CoInitialize(NULL);
CComPtr<IHTMLDocument2> pDoc2;
string strTemp="";
HINSTANCE hinst=::LoadLibrary("OLEACC.DLL");
if(hinst!=NULL) {
LRESULT lres;
UINT unMsg=::RegisterWindowMessage(_T("WM_HTML_GETOBJECT"));
::SendMessageTimeout(hwndIE,unMsg,0L,0L,SMTO_ABORTIFHUNG,1000,(DWORD*)&lres);
LPFNOBJECTFROMLRESULT pfObjectFromLresult=(LPFNOBJECTFROMLRESULT)::GetProcAddress(hinst,_T("ObjectFromLresult"));
if(pfObjectFromLresult!=NULL) {
HRESULT hres;
hres=(*pfObjectFromLresult)(lres,IID_IHTMLDocument2,0,(void**)&pDoc2);
if(SUCCEEDED(hres)) {
CComPtr<IHTMLElement> pHtmlElem;
hres=pDoc2->get_body(&pHtmlElem);
BSTR bstrText=NULL;
pHtmlElem->get_innerText(&bstrText);
_bstr_t _bstrTemp(bstrText,false);
//strTemp=(char*)_bstr_t(bstrText);
strTemp=(char*)_bstrTemp;
}
}
::FreeLibrary(hinst);
}
CoUninitialize();
好了,现在strTemp中已经包含了Internet Explorer_Server窗口的内容了。
对了,记得包含头文件:
[cpp] view plaincopyprint?#include <mshtml.h>
#include <atlbase.h>
#include <oleacc.h>
#include <string>
#include <comdef.h>
using std::string;
CoInitialize(NULL);
CComPtr<IHTMLDocument2> pDoc2;
string strTemp="";
HINSTANCE hinst=::LoadLibrary("OLEACC.DLL");
if(hinst!=NULL) {
LRESULT lres;
UINT unMsg=::RegisterWindowMessage(_T("WM_HTML_GETOBJECT"));
::SendMessageTimeout(hwndIE,unMsg,0L,0L,SMTO_ABORTIFHUNG,1000,(DWORD*)&lres);
LPFNOBJECTFROMLRESULT pfObjectFromLresult=(LPFNOBJECTFROMLRESULT)::GetProcAddress(hinst,_T("ObjectFromLresult"));
if(pfObjectFromLresult!=NULL) {
HRESULT hres;
hres=(*pfObjectFromLresult)(lres,IID_IHTMLDocument2,0,(void**)&pDoc2);
if(SUCCEEDED(hres)) {
CComPtr<IHTMLElement> pHtmlElem;
hres=pDoc2->get_body(&pHtmlElem);
BSTR bstrText=NULL;
pHtmlElem->get_innerText(&bstrText);
_bstr_t _bstrTemp(bstrText,false);
//strTemp=(char*)_bstr_t(bstrText);
strTemp=(char*)_bstrTemp;
}
}
::FreeLibrary(hinst);
}
CoUninitialize();
CoInitialize(NULL);
CComPtr<IHTMLDocument2> pDoc2;
string strTemp="";
HINSTANCE hinst=::LoadLibrary("OLEACC.DLL");
if(hinst!=NULL) {
LRESULT lres;
UINT unMsg=::RegisterWindowMessage(_T("WM_HTML_GETOBJECT"));
::SendMessageTimeout(hwndIE,unMsg,0L,0L,SMTO_ABORTIFHUNG,1000,(DWORD*)&lres);
LPFNOBJECTFROMLRESULT pfObjectFromLresult=(LPFNOBJECTFROMLRESULT)::GetProcAddress(hinst,_T("ObjectFromLresult"));
if(pfObjectFromLresult!=NULL) {
HRESULT hres;
hres=(*pfObjectFromLresult)(lres,IID_IHTMLDocument2,0,(void**)&pDoc2);
if(SUCCEEDED(hres)) {
CComPtr<IHTMLElement> pHtmlElem;
hres=pDoc2->get_body(&pHtmlElem);
BSTR bstrText=NULL;
pHtmlElem->get_innerText(&bstrText);
_bstr_t _bstrTemp(bstrText,false);
//strTemp=(char*)_bstr_t(bstrText);
strTemp=(char*)_bstrTemp;
}
}
::FreeLibrary(hinst);
}
CoUninitialize();
好了,现在strTemp中已经包含了Internet Explorer_Server窗口的内容了。
对了,记得包含头文件:
[cpp] view plaincopyprint?#include <mshtml.h>
#include <atlbase.h>
#include <oleacc.h>
#include <string>
#include <comdef.h>
using std::string;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
微测检测5.10
2023-07-11 广告
2023-07-11 广告
IEC62133与en62133的区别如下:1. 认证机构不同:IEC62133是国际的标准,它以国际通用的标准进行生产;而en62133采用的是欧盟的标准,它使用欧盟的生产需求进行生产。2. 宗旨不同:IEC62133的宗旨是促进电气、电...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询