根据Internet Explorer_Server窗口得到IHtmlDocument2接口
2013-05-09 14:54
316 查看
根据Internet Explorer_Server窗口得到IHtmlDocument2接口 |
作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站 |
代码很少,自己看 #include <mshtml.h> #include <atlbase.h> #include <oleacc.h> BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam) { TCHAR buf[100]; ::GetClassName( hwnd, (LPTSTR)&buf, 100 ); if ( _tcscmp( buf, _T("Internet Explorer_Server") ) == 0 ) \ { *(HWND*)lParam = hwnd; return FALSE; } else return TRUE; }; //You can store the interface pointer in a member variable //for easier access void CDlg::OnGetDocInterface(HWND hWnd) { CoInitialize( NULL ); // Explicitly load MSAA so we know if it's installed HINSTANCE hInst = ::LoadLibrary( _T("OLEACC.DLL") ); if ( hInst != NULL ) { if ( hWnd != NULL ) { HWND hWndChild=NULL; // Get 1st document window ::EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild ); if ( hWndChild ) { CComPtr<IHTMLDocument2> spDoc; LRESULT lRes; UINT nMsg = ::RegisterWindowMessage( _T("WM_HTML_GETOBJECT") ); ::SendMessageTimeout( hWndChild, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes ); LPFNOBJECTFROMLRESULT pfObjectFromLresult = (LPFNOBJECTFROMLRESULT)::GetProcAddress( hInst, _T("ObjectFromLresult") ); if ( pfObjectFromLresult != NULL ) { HRESULT hr; hr = (*pfObjectFromLresult)( lRes, IID_IHTMLDocument, 0, (void**)&spDoc ); if ( SUCCEEDED(hr) ) { CComPtr<IDispatch> spDisp; CComQIPtr<IHTMLWindow2> spWin; spDoc->get_Script( &spDisp ); spWin = spDisp; spWin->get_document( &spDoc.p ); // Change background color to red spDoc->put_bgColor( CComVariant("red") ); } } } // else document not ready } // else Internet Explorer is not running ::FreeLibrary( hInst ); } // else Active Accessibility is not installed CoUninitialize(); } |
相关文章推荐
- 根据Internet Explorer_Server窗口得到IHtmlDocument2
- 根据Internet Explorer_Server窗口得到IHtmlDocument2接口(IE编程)
- 根据Internet Explorer_Server窗口得到IHtmlDocument2接口
- 如何得到网页中所有内嵌框架的IHTMLDocument2接口
- 已知IE窗口的句柄,如何由此得到IHTMLdocument2接口?
- 已知IWebBrowser2接口,如何获得其Internet Explorer_Server窗口句柄?
- delphi中Ihtmldocument2接口的使用
- IE的BHO通过IHTMLDocument2接口获得网页源代码
- delphi中Ihtmldocument2接口的使用
- 根据process id和窗口名得到窗口句柄
- Camshift原理 camshift利用目标的颜色直方图模型将图像转换为颜色概率分布图,初始化一个搜索窗的大小和位置,并根据上一帧得到的结果自适应调整搜索窗口的位置和大小,从而定位出当前图像中目标的
- 也谈根据IE窗口句柄hWnd获得IWebBrowser接口
- 关于根据pid得到主窗口。
- 获取ie窗口的IHTMLDocument2对象
- 用IHTMLDocument2接口获取页面上想要的数据,代替正则表达式
- 根据天气接口获取其中的数据
- selenium webdriver学习(六)-怎么得到弹出窗口
- 打开新窗口,并且父窗口得到新窗口的返回值,比如论坛头像的选择,对firefox同样适合
- #269 – 根据内容自动改变窗口的大小(Automatically Sizing a Window to Fit Its Contents)
- 根据扩展名得到HICON