HTML Editor for CBuilder/Delphi

别说谁变了你拦得住时间么 提交于 2019-12-05 00:31:42

问题


I need to find basic WYSIWYG HTML editor component for C++Builder 5 to let users to create some simple text that I will paste into existing HTML page template. Just a simple support to create links, add images, use headers/bold/italic.


回答1:


You can drop a TWebBrowser on a form and enable designmode on it, like this:

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

After executing the above line, the page will be editable. You can type extra text, delete, etc. If you want to make selections bold or insert images, you're going to have to add some buttons to program that. The cool thing is that you can do that either from Delphi (or C++ builder in your case) or you can add javascript on the page to edit itself.

The contents of the page can be retrieved from

(WebBrowser.Document as IHTMLDocument2).body.innerHTML;

Remember that (WebBrowser.Document as IHTMLDocument2) could be nil.


Anyway, I can imagine that there are components around that do all the work for you, which is probably a better route to take than reinventing the wheel.




回答2:


I would recommend TRichView due to its world class support, and deep feature set. While it is not a true "HTML" editor, it does support the ability to export to HTML, even generating the appropriate CSS styles if necessary. I use it for handling the email portion of our main product and it works very well. Internally the storage is either RTF (extended to support images better), or as a proprietary format. There are plenty of examples of a simple editors which would easily suit your needs.




回答3:


in C++ Builder, it would be something like this:

(wb is a 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();
        }
}
//---------------------------------------------------------------------------



回答4:


http://www.bsalsa.com/

supplies a free set of EmbeddedWebBrowser components with an Edit Designer component that you link to the EmbeddedBrowser window to control design mode and have edit control save to file, insert links, images, etc...

seems to work well!



来源:https://stackoverflow.com/questions/402455/html-editor-for-cbuilder-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!