wxHTML quick start

Displaying HTML

First of all, you must include <wx/wxhtml.h>.

Class wxHtmlWindow (derived from wxScrolledWindow) is used to display HTML documents. It has two important methods: LoadPage and SetPage. LoadPage loads and displays HTML file while SetPage displays directly the passed string. See the example:

    mywin -> LoadPage("test.htm");
    mywin -> SetPage("<html><body>"
                     "<h1>Error</h1>"
		     "Some error occurred :-H)"
		     "</body></hmtl>");

I think the difference is quite clear.

Displaying Help

See wxHtmlHelpController.

Setting up wxHtmlWindow

Because wxHtmlWindow is derived from wxScrolledWindow and not from wxFrame, it doesn't have visible frame. But the user usually wants to see the title of HTML page displayed somewhere and the frame's titlebar is the ideal place for it.

wxHtmlWindow provides 2 methods in order to handle this: SetRelatedFrame and SetRelatedStatusBar. See the example:

    html = new wxHtmlWindow(this);
    html -> SetRelatedFrame(this, "HTML : %%s");
    html -> SetRelatedStatusBar(0);

The first command associates the HTML object with its parent frame (this points to wxFrame object there) and sets the format of the title. Page title "Hello, world!" will be displayed as "HTML : Hello, world!" in this example.

The second command sets which frame's status bar should be used to display browser's messages (such as "Loading..." or "Done" or hypertext links).

Customizing wxHtmlWindow

You can customize wxHtmlWindow by setting font size, font face and borders (space between border of window and displayed HTML). Related functions:

The last two functions are used to store user customization info wxConfig stuff (for example in the registry under Windows, or in a dotfile under Unix).

ymasuda 平成17年11月19日