根据Internet Explorer_Server窗口得到IHtmlDocument2接口 (转)

根据Internet Explorer_Server窗口得到IHtmlDocument2接口 (转)[@more@]

代码很少,自己看

#include
#include
#include

BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
{
 TCHAR buf[100];

 ::GetClassName( hwnd, (LPTSTR)&buf, 100 );
 if ( _tcscmp( buf, _T("Inte.NET 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 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 spDisp;
 CComQIPtr 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();
}


来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-991340/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10752043/viewspace-991340/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值