HTML Editor for CBuilder / Delphi

I need to find the main component of the WYSIWYG HTML editor for C ++ Builder 5 so that users can create simple text that I paste into an existing HTML page template. Just simple support for creating links, adding images, using headings / bold / italic.

+5
source share
4 answers

You can remove TWebBrowser in the form and include the structure in it, for example:

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

After completing the above line, the page will be available for editing. You can enter additional text, delete, etc. If you want to make the selection in bold or insert images, you will need to add a few buttons to program it. The best part is that you can do this either using Delphi (or C ++ builder in your case), or you can add javascript on the page to edit yourself.

Page content can be obtained from

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

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


In any case, I can imagine that there are components around that do all the work for you, which is probably a better way than reinventing the wheel.

+7
source

I would recommend TRichView because of its world-class support and deep feature set. Although not a true HTML editor, it supports the ability to export to HTML, even generating appropriate CSS styles if necessary. I use it to process the email of our main product, and it works very well. The internal storage is RTF (enhanced to support images better) or as a proprietary format. There are many examples of simple editors that easily fit your needs.

+4
source

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

(wb is 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(); } } //--------------------------------------------------------------------------- 
+1
source

http://www.bsalsa.com/

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

seems to work well!

+1
source

All Articles