#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;
};
void
CDlg::OnGetDocInterface(
HWND
hWnd)
{
CoInitialize( NULL );
HINSTANCE
hInst = ::LoadLibrary( _T(
"OLEACC.DLL"
) );
if
( hInst != NULL )
{
if
( hWnd != NULL )
{
HWND
hWndChild=NULL;
::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_IHTMLDocument2, 0, (
void
**)&spDoc );
if
( SUCCEEDED(hr) )
{
spDoc->put_bgColor( CComVariant(
"red"
) );
}
}
}
}
::FreeLibrary( hInst );
}
CoUninitialize();
}</ihtmldocument2></oleacc.h></atlbase.h></mshtml.h>