用TCppWebBrowser来浏览htm文件,怎样加上背景色?

cjm29 2003-09-15 11:26:18

用TCppWebBrowser来浏览htm文件,怎样加上背景色?怎样加上背景图片?
谢谢啦!
...全文
97 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccrun.com 2003-09-15
  • 打赏
  • 举报
回复
通过IHTMDLDocument2接口可以实现改变IE背景色,至于加上背景图片,我想应该也行吧。没有试过。
jishiping 2003-09-15
  • 打赏
  • 举报
回复
背景色是由htm文件指定的吧。
ccrun.com 2003-09-15
  • 打赏
  • 举报
回复
恩。能对你有帮助就行。也不枉俺搞这段程序。
cjm29 2003-09-15
  • 打赏
  • 举报
回复
多谢老妖的指点,那段代码我已经准备用上去了。
ccrun.com 2003-09-15
  • 打赏
  • 举报
回复
参考自:http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q249/2/32.ASP&NoWebContent=1
ccrun.com 2003-09-15
  • 打赏
  • 举报
回复
以下代码改变CppWebBrowser中网页的背景为红色:

Form上放置一个TCppWebBrowser,两个Button,点击Button1打开一个网页,点击Button2改变其背景颜色为红色。

//---------------------------------------------------------------------------
#include <vcl.h>
#include <mshtml.h>
#include "atl\\atlbase.h"
#include <oleacc.h>

#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SHDocVw_OCX"
#pragma resource "*.dfm"
TForm1 *Form1;
void OnGetDocInterface(HWND hWnd);
BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam);
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
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 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;
//找到Internet Explorer_Server的名柄
::EnumChildWindows( hWnd, (WNDENUMPROC)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 );
//将背景颜色改为红色,可以自己修改。
spDoc->put_bgColor( CComVariant("red") );
}
}
} // else document not ready
} // else Internet Explorer is not running
::FreeLibrary( hInst );
} // else Active Accessibility is not installed
CoUninitialize();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
CppWebBrowser1->Navigate(L"http://www.ccrun.com");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
OnGetDocInterface(CppWebBrowser1->Handle);
}
//---------------------------------------------------------------------------


代码在Windows 2000 ADV Server + BCB 6.0上测试通过。

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧