<

C++ Builder and Dynamic HTML

Published on
13,256 Points
7,156 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

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Join & Write a Comment

The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month