首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

如何利用cppwebbrowse显示指定的内容

2013-04-09 
怎么利用cppwebbrowse显示指定的内容。因为HTML格式所做出来的报表比较好看,所以我想用cppwebbrowse来显示H

怎么利用cppwebbrowse显示指定的内容。
因为HTML格式所做出来的报表比较好看,所以我想用cppwebbrowse来显示HTML格式的网页报表,想问一下,如果才能让cppwebbrowse显示指定的内容(并不是指定URL的内容),比如我有用一个string加载了网页的源代码程序,怎么让他显示在cppwebbrowse控制里呢? html 报表 cppwebbrowse
[解决办法]

__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
    CppWebBrowser1->Navigate(L"about:blank");
}

#include <mshtml.h>

// ---------------------------------------
BOOL __stdcall CrnWriteHtmlContent(IHTMLDocument2 *spDoc, LPWSTR lpText)
{
    BOOL bResult = FALSE;
    if (NULL == spDoc) return bResult;

    BSTR p = ::SysAllocString(lpText);
    try
    {
        VARIANT *param;
        SAFEARRAY *psfArray = SafeArrayCreateVector(VT_VARIANT, 0, 1);
        SafeArrayAccessData(psfArray, (LPVOID *)&param);
        param->vt = VT_BSTR;
        param->bstrVal = p;
        SafeArrayUnaccessData(psfArray);

        spDoc->write(psfArray);
        SafeArrayDestroy(psfArray);

        spDoc->close();

        bResult = TRUE;
    }
    __finally
    {
        ::SysFreeString(p);
    }
    
    return bResult;
}

// ---------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    IHTMLDocument2 *spDoc = NULL;
    HRESULT hr = CppWebBrowser1->Document->QueryInterface(
            ::IID_IHTMLDocument2, (void **)&spDoc);

    if (SUCCEEDED(hr))
    {
        CrnWriteHtmlContent(spDoc, WideString(Memo1->Lines->Text));

        spDoc->Release();
    }

}


假设Memo中的内容是:
<font color="red">Memo1</font>
<br>
<font color="blue">Memo1</font>
<br>
<a href="http://www.ccrun.com">链接</a>


运行后就看到效果了。

热点排行