Currently viewing: GipsySoft » Front Page» QHTM

How to give HTML to QHTM

There are four ways to put HTML into the QHTM control. The Windows API example demonstrates most of these techniques.

As the caption of the control
When you create a QHTM control, either in a dialog resource script or by using CreateWindow(Ex)(...) you have the opportunity to set some caption text for the window. This is the actual text that QHTM will use initially. You can leave it blank with no problems but you can remove initialisation code if you set yoru initial text here.

As text
Windows allow you to set the caption text of a window by using the API SetWindowText(...) or by sending the control a WM_SETTEXT message. QHTM is no different and will accept HTML in either of these formats.

From a file
This is the easiest method to manage, especially if you have designers working on the HTML as it allows your program to be built first and the HTML loaded from disk without any need for the designers to compile your software.

See also QHTM_PrintSetTextFile

From resources
You should use this option if you want to your application to survive without any supporting files. Great if you have a small application with lots of HTML content as it saves disk space.

To add a HTML file to your resources you will probably have to edit your resource script by hand. This isn't as bad as your think. This is an extract from the MFC example's RC2 file:

LOGO.PNG                RCDATA  DISCARDABLE     "res\\logo.png"
ID_ABOUT_HTML_RESOURCE  RCDATA  DISCARDABLE     "res\\about.html"
ID_DEFAULT_HTML         RCDATA  DISCARDABLE     "res\\Default.html"
ABOUT.PNG               RCDATA  DISCARDABLE     "res\\About.png"
REFRESH.PNG             RCDATA  DISCARDABLE     "res\\Refresh.png"
You can see that the HTML pages have symbolic IDs as any other resource type has, but the images have their names as their IDs. You do not need to add the image names as IDs as your resource compiler should cope with this.

Note that you can use either RT_RCDATA or RT_HTML as the resource type as QHTM will happily load either.

See also QHTM_PrintSetTextResource

But how does QHTM find images?
When QHTM comes across an image in your HTML it looks for a a marker, "RES:", at the start of the image name, if it finds this marker then it reads the image from the resources e.g.

<img src="RES:logo.png">
will force the image to be read from the resource named "logo.png". If QHTM fails to find the image, or the "RES:" tag then it assumes the image name refers to a disk file and will attempt to read that. If that fails then the file cannot be found and QHTM will display it's standard image for a missing image.