Internet Explorer_Server内容获取

首先这里假设你已经获取到Internet Explorer_Server窗口的句柄,假设为hwndIE:HWND。
头文件
#include <mshtml.h>    
#include <atlbase.h>    
#include <oleacc.h>   
#include <string>   
#include <comdef.h>   
using std::string;
VOID GetStr(HWND hwndIE)
{
CoInitialize(NULL);  
CComPtr<IHTMLDocument2> pDoc2;  
string strTemp = "";  
HINSTANCE hinst = LoadLibraryA("OLEACC.DLL");  
if(hinst != NULL) {  
LRESULT lres;  
UINT unMsg = RegisterWindowMessageA("WM_HTML_GETOBJECT");  
SendMessageTimeoutA(hwndIE, unMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (PDWORD_PTR)&lres);  
LPFNOBJECTFROMLRESULT pfObjectFromLresult=(LPFNOBJECTFROMLRESULT)::GetProcAddress(hinst, "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*)_bstrTemp;  
}  
}  
FreeLibrary(hinst);  
}  


CoUninitialize(); 
}
好了,现在strTemp中已经包含了Internet Explorer_Server窗口的内容了。

没有更多推荐了,返回首页