ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 根据Internet Explorer_Server窗口得到IHtmlDocument2接口 (转)

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

原创 Linux操作系统 作者:WebSnap 时间:2019-04-18 14:00:05 0 删除 编辑
根据Internet Explorer_Server窗口得到IHtmlDocument2接口 (转)

代码很少,自己看

#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/10797429/viewspace-101629/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-04

  • 博文量
    174
  • 访问量
    127223