Home > c++ > Making a simple html editor in C++ Builder

Making a simple html editor in C++ Builder

Back in time, I had to make a simple html editor. It was very easy, by using a simple TCppWebBrowser (wb) and the IHTMLDocument2 interface. You will also need a TMemo (memo1) control. Here is the source code, hope it helps someone :)






//---------------------------------------------------------------------------
//author: Adrián Deccico - http://adrian.org.ar
//---------------------------------------------------------------------------

#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. free
    September 9th, 2010 at 08:47 | #1

    great…

  2. hmm…?
    October 12th, 2010 at 23:53 | #2

    thanks

  1. No trackbacks yet.