您现在的位置: 中国教师站 >> 教师关注 >> 电脑技术 >> 编程技术 >> Visual C >> 正文

Google
根据Internet Explorer_Server窗口得到IHtmlDocument2
作者:Siny 文章来源:中国教师站cn-teacher 点击数: 更新时间:2007-4-22 12:49:17

代码很少,自己看

#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();
}

相关专题:
 
 网友评论:(评论内容只代表网友观点,与本站立场无关!)
GOOGLE广告

阅读排行

| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 |
中国教师站

中国教师站 版权所有 Copyright © 2006-2020 All Rights Reserved 站长:Sina & Siny
[备用域名:www.JXZYW.Com] 有事请留言有事请留言
【实力成就精品 诚信呵护品牌】

信息产业部备案
苏ICP备06018635号