<

Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x

C++ Builder and Dynamic HTML

Published on
12,878 Points
6,778 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Join & Write a Comment

This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month