我需要为C ++ Builder 5找到基本的WYSIWYG HTML编辑器组件,以便用户创建一些我将粘贴到现有HTML页面模板中的简单文本。 只需简单的支持即可创建链接,添加图像,使用标题/粗体/斜体。

有帮助吗?

解决方案

您可以在表单上删除TWebBrowser并在其上启用designmode,如下所示:

// Delphi code..
(WebBrowser1.Document as IHTMLDocument2).designMode := 'on';

执行上述行后,页面将可编辑。您可以键入额外的文本,删除等。如果您想要选择粗体或插入图像,您将不得不添加一些按钮来编程。很酷的是,你可以从Delphi(或你的C ++构建器)中做到这一点,或者你可以在页面上添加javascript来编辑自己。

可以从

中检索页面内容
(WebBrowser.Document as IHTMLDocument2).body.innerHTML;

请记住(WebBrowser.Document为IHTMLDocument2)可能为零。


无论如何,我可以想象周围的组件可以为你完成所有工作,这可能是一条比重新发明轮子更好的选择。

其他提示

由于其世界级的支持和深入的功能集,我建议 TRichView 。虽然它不是真正的“HTML”。编辑器,它确实支持导出到HTML的能力,甚至在必要时生成适当的CSS样式。我用它来处理我们主要产品的电子邮件部分,它运作良好。在内部,存储是RTF(扩展为更好地支持图像),或者是专有格式。有很多简单的编辑器可以轻松满足您的需求。

在C ++ Builder中,它将是这样的:

(wb是TCppWebBrowser)

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "mshtml.h"

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "SHDocVw_OCX"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnNavigateAndEditClick(TObject *Sender)
{
        wb->Navigate((WideString)"www.google.com");
        while (wb->Busy)
                Application->ProcessMessages();

        if (wb->Document)
        {
                IHTMLDocument2 *html;
                wb->Document->QueryInterface<IHTMLDocument2>(&html);
                html->put_designMode(L"On");
                html->Release();
        }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnInsertImageClick(TObject *Sender)
{
    if (wb->Document)
    {
          IHTMLDocument2 *html;
          wb->Document->QueryInterface<IHTMLDocument2>(&html);
          VARIANT var;
          VARIANT_BOOL receive;
          html->execCommand(L"InsertImage",true,var, &receive);
          html->Release();
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnGetHtmlClick(TObject *Sender)
{
        if (wb->Document)
        {
                IHTMLDocument2 *html;
                wb->Document->QueryInterface<IHTMLDocument2>(&html);
                IHTMLElement *pElement;
                html->get_body(&pElement);
                pElement->get_parentElement(&pElement);
                wchar_t *tmp;
                pElement->get_outerHTML(&tmp);
                Memo1->Lines->Text = tmp;
                pElement->Release();
                html->Release();
        }
}
//---------------------------------------------------------------------------

http://www.bsalsa.com/

提供一组免费的 EmbeddedWebBrowser 组件和一个Edit Designer组件 链接到 EmbeddedBrowser 窗口以控制设计模式并具有编辑控件 保存到文件,插入链接,图像等...

似乎运作良好!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top