<

C++ Builder and Dynamic HTML

Published on
13,376 Points
7,276 Views
1 Endorsement
Last Modified:
Approved
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ...

Some objects defined and used in this source include:

   THTMLEvent
   THTMLElement
   THTMLTxtRange
   THTMLStyleSheet
   THTMLDocument
   THTMLTable , ....


Steps to use this code:

1

Put a TWebBrowser component on your form.

2

Put a TButton component on your form.

3

Define an instance of THTMLDocument:
THTMLDocument document; //in global scope

Open in new window

4

In your OnButtonClick event, write this code:
WebBrowser1->Navigate("http://www.google.com");  // test with this URL

Open in new window

5

In your OnWebBrowser1DocumentComplete handler, write this code:
document.webBrowser = WebBrowser1;

Open in new window

6

Now the document object is ready to use.
Sample usage:
THTMLElement elm = document.getElementById("gog");
ShowMessage(elm.innerHTML);

Open in new window

7

For event handling needs, define a global instance of THTMLElement:
THTMLElement myElm;

Open in new window

8

In your OnWebBrowser1DocumentComplete handler, write this code:
document.webBrowser = WebBrowser1;
myElm = document.getElementById("gog");
myElm.onclick = &OnClick;

Open in new window

9

OnClick defines as:
In public section of TForm1 write:
void OnClick();

Open in new window

...and in the CPP file write:
void TForm1::OnClick()
{
     THTMLEventObj event = document.parentWindow.event;
     ShowMessage(event.x); // mouse pos
     ShowMessage(event.ctrlKey); // if ctrl pressed
     event.returnValue = 0; // for cancel event
...
}

Open in new window

Notes:
Supported: BCB 2009, 2010
Not supported BCB XE yet;

Files:
html.cpp
html.h
1
Comment
Author:taghia
0 Comments

Featured Post

Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Join & Write a Comment

This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month