QHTM

Ultra small Win32 HTML control.

Using QHTM you can place HTML content on any window, any device context, on a report, on a button or even in a tooltip.  QHTM is written entirely in C++ and does not rely on MFC, nor does it need IE installed.  Instead QHTM uses direct Win32 API calls which makes it very fast and very light.

The control also provides ability to display QHTM Button, Tooltip or ListBox.  Cool Tooltips are enabled by default.

Summary
QHTMUltra small Win32 HTML control.
AddAdd QHTM control.
AddHtmlAdd HTML to the current document.
AdjustControlAdjust control’s height to fit HTML.
FormResetResets the form
FormSubmitSubmits the form
FormSetSubmitCallbackSet the function to call when submitting a form via POST
GetDrawnSizeGet the width and height of the HTML
GetHTMLHeightGiven a width determine the height of some HTML.
GetHTMLReturn HTML rendered by the control
GotoLinkForce the HTML control to scroll to a named linked within a document.
InitInitialise the QHTM module.
LoadFromFileLoad HTML into QHTM passing a valid filename.
LoadFromResourceLoad HTML into QHTM from a resource
MsgBoxMsgBox replacement
PrintCreateContextCreate and return a print context.
PrintDestroyContextDestroy a valid QHTMCONTEXT.
PrintSetTextSet the HTML for the given print context.
PrintSetTextFileSet the HTML for the given print context using a file.
PrintLayoutLayout the HTML, using the HDC passed, to determine the number of pages.
PrintPagePrint a page
PrintGetHTMLHeightGiven a fixed width it returns the rendered height of the HTML.
RenderHTMLRender HTML onto a device context.
RenderHTMLRectRender HTML onto a device context and confined within a rectangle.
SetHTMLButtonChange a button so that it can contain HTML as it’s text instead of plain text.
SetHTMLListboxChange a listbox so that it’s items can use HTML instead of plain text.
ShowScrollbarsSet whether or not QHTM will display scrollbars.
ZoomZoom the HTML in or out
Links
About

Add

QHTM_Add(Hwnd,  
X,  
Y,  
W,  
H,  
Text = "",
Style = "",
Handler = "",
DllPath = "")

Add QHTM control.

Parameters

HwndHandle of the parent.
X-HControl coordinates.
TextHTML to display.
StyleList of control styles, optional.
HandlerNotification handler, optional.
DllPathPath to the control’s dll, optional.  By default current folder.  The dll name must be qhtml.dll.

Styles

BorderAdd border arond the control.
TransparentMake HTML control transparent.

Returns

Controls handle or error message.

Handler

Result := Handler(Hwnd, Link, Id)
HwndHandle of the control.
LinkLink text.
IDHTML link ID.
ResultReturn 1 to open the link in system default editor.

AddHtml

QHTM_AddHtml(hCtrl,  
HTML,  
bScroll = false)

Add HTML to the current document.  If there is no document then one is created.

Parameters

HTMLQHTML to add to the control
bScrollSet to TRUE to scroll to the end, by default false

AdjustControl

QHTM_AdjustControl(hCtrl)

Adjust control’s height to fit HTML.

Parameters

hCtrlControl

Remarks

This function is to be used in combination with SetHTMLButton or <SetHTMLListBox>.

FormReset

QHTM_FormReset(hCtrl,
FormName)

Resets the form

Parameters

FormNameName of the HTML form

Returns

Non-zero if the form is found and reset

FormSubmit

QHTM_FormSubmit(hCtrl,
FormName)

Submits the form

Parameters

FormNameName of the HTML form

Returns

Non-zero if the form is found and submitted

FormSetSubmitCallback

QHTM_FormSetSubmitCallback(hCtrl,
Fun)

Set the function to call when submitting a form via POST

Parameters

FunFunction to be called

Callback function

OnQHtmForm(FormName, Method, FieldCount, Fields)
FormNameName of the form that was submited
ActionAction of the form
FieldCountNumber of fields in the form
FieldsNew line separated list of filed names and values.

GetDrawnSize

QHTM_GetDrawnSize( hCtrl,
ByRef w,
ByRef h)

Get the width and height of the HTML

Parameters

w, hReference to variables to receive width and height

GetHTMLHeight

QHTM_GetHTMLHeight(DC,
HTML,
Width)

Given a width determine the height of some HTML.

Parameters

DCDevice context use for measuring.
HTMLHTML content.
WidthConstraining width.

Returns

Measured height of the HTML.

GetHTML

QHTM_GetHTML(hCtrl)

Return HTML rendered by the control

Returns

HTML

GotoLink

QHTM_GotoLink(hCtrl,
LinkName)

Force the HTML control to scroll to a named linked within a document.  Useful if you have a large document and want to bring a particular section to the users attention.

Parameters

LinkNameSname of the link you wish to navigate to

Init

QHTM_Init(DllPath = "qhtm.dll")

Initialise the QHTM module.

Parameters

DllPathPath to the qhtml dll.

Remarks

You generally don’t need to call this function, unless dll is not in the standard place.

Returns

TRUE on success or FALSE otherwise.

LoadFromFile

QHTM_LoadFromFile(hCtrl,
FileName)

Load HTML into QHTM passing a valid filename.

Parameters

FileNameName of the file with QHTML

Returns

Non-zero if it succeeds.

Remarks

QHTML can include other files with the following directive inside html comment:

<!-- #include virtual="path"-->

LoadFromResource

QHTM_LoadFromResource(hCtrl,  
Name,  
Resource = "")

Load HTML into QHTM from a resource

Parameters

NameResource name or number.
ResourceResource file, leave empty for compiled scripts to use its exe.

Remarks

In order to use this feasture you must add resources manually using Resource Hacker or some other resource editor.

Examples

QHTM_LoadFromResource(hQhtm, 1)     ;load resource with ID=1 from compiled script
QHTM_LoadFromResource(hQhtm, "ABOUT.HTML", "res.dll") ; load resource by name from dll

MsgBox

QHTM_MsgBox(HTML,  
Caption = "",
Type = "",
HGui =  0)

MsgBox replacement

Parameters

HTMLText to be shown in html format
CaptionOptional window caption
TypeSpace separated list of MessageBox types: ABORTRETRYIGNORE CANCELTRYCONTINUE COMPOSITE DEFAULT_DESKTOP_ONLY DEFBUTTON1 DEFBUTTON2 DEFBUTTON3 DEFBUTTON4 ERR_INVALID_CHARS DEFMASK FUNC HELP ICONASTERISK ICONHAND ICONEXCLAMATION ICONMASK ICONQUESTION MISCMASK MODEMASK NOFOCUS OK PRECOMPOSED OKCANCEL RETRYCANCEL RIGHT RTLREADING SETFOREGROUND SYSTEMMODAL TASKMODAL YESNO YESNOCANCEL USERICON USEGLYPHCHARS TYPEMASK TOPMOST ICONWARNING
HGuiGUI handle (optional)

Returns

Non-zero if it succeeds.

Example

QHTM_MessageBox(“Do you <b>really</b> want to format drive C ?”, “Format”, “YESNOCANCEL ICONWARNING DEFBUTTON3”, hGui)

PrintCreateContext

QHTM_PrintCreateContext()

Create and return a print context.  The first function called when printing.  Creates and initialises internal structures for printing.

Returns

A valid print context, 0 if an error occurs.

PrintDestroyContext

QHTM_PrintDestroyContext(Context)

Destroy a valid QHTMCONTEXT.

Parameters

ContextThe print context to destroy.

Returns

Non-zero if no error.

PrintSetText

QHTM_PrintSetText(Context,
HTML)

Set the HTML for the given print context.

Parameters

Context- The print context.  HTML - HTML document to print.

Returns

Non-zero if it succeeds.

PrintSetTextFile

QHTM_PrintSetTextFile(Context,
FileName)

Set the HTML for the given print context using a file.

Parameters

ContextThe print context.
FilenameFilename to the HTML document.

Returns

Non-zero if it succeeds.

PrintLayout

QHTM_PrintLayout(Context,
DC,
PRECT)

Layout the HTML, using the HDC passed, to determine the number of pages.

Parameters

ContextThe print context.
DCThe device context used to print.
PRECTPointer to the rectangle on the page that the HTML will be restricted to.

Returns

Number of pages

PrintPage

QHTM_PrintPage(Context,
DC,
PageNum,
PRECT)

Print a page

Parameters

ContextThe print context.
DCThe device context used to print.
PageNumThe page number to print.
PRECTPointer to the rectangle on the page that the HTML will be restricted to.

Returns

Non-zero if it succeeds.

PrintGetHTMLHeight

QHTM_PrintGetHTMLHeight(DC,  
HTML,  
PrintWidth,  
ZoomLevel = 2)

Given a fixed width it returns the rendered height of the HTML.  Used to determine how much HTML will fit on a single page or within a particular bounding width.

Parameters

DCThe device context used to measure the HTML document.
HTMLHTML document to measure
PrintWidthin pixels, of the area that the HTML document will be restricted to.
ZoomLevelThe zoom level to print at.  Can be between 0 and 4.

Return value

The height of the HTML given a width.

RenderHTML

QHTM_RenderHTML(DC,
HTML,
Width)

Render HTML onto a device context.

Parameters

DCHandle of the device context.
HTMLHTML to render.
WidthConstraining width.

Returns

Non-zero if it succeeds.

RenderHTMLRect

QHTM_RenderHTMLRect(DC,
HTML,
PRECT)

Render HTML onto a device context and confined within a rectangle.

Parameters

DCHandle of the device context
HTMLHTML to render
PRECTPointer to RECT

Returns

Non-zero if it succeeds.

SetHTMLButton

QHTM_SetHTMLButton(hButton,  
Adjust = false)

Change a button so that it can contain HTML as it’s text instead of plain text.

Parameters

hButtonHandle of the button.
AdjustSet to TRUE to adjust controls height after HTML is drawn.

Returns

TRUE on success

SetHTMLListbox

QHTM_SetHTMLListbox(hListbox,  
Adjust =  true)

Change a listbox so that it’s items can use HTML instead of plain text.

Parameters

hListboxHandle of the ListBox

Returns

TRUE on success

Remarks

Currently, this function shouldn’t be used as it produces side-effects on painting routine of Main Window and some other side effects.  Also, in order to work ListBox must be created with one of the LBS_OWNERDRAW styles (0x10 0x20)

ShowScrollbars

QHTM_ShowScrollbars(hCtrl,
bShow)

Set whether or not QHTM will display scrollbars.  This overrides QHTM’s ability to automatically display scrollbars where needed.

Parameters

bShowSet to TRUE to show scrollbars or FALSE to hide them

Zoom

QHTM_Zoom(hCtrl,  
Level = 2)

Zoom the HTML in or out

Parameters

LevelZoom level, from 0 to 4.  2 represents actual size.

Returns

Non-zero on success

Links

About

QHTM_Add(Hwnd,  
X,  
Y,  
W,  
H,  
Text = "",
Style = "",
Handler = "",
DllPath = "")
Add QHTM control.
QHTM_AddHtml(hCtrl,  
HTML,  
bScroll = false)
Add HTML to the current document.
QHTM_AdjustControl(hCtrl)
Adjust control’s height to fit HTML.
QHTM_FormReset(hCtrl,
FormName)
Resets the form
QHTM_FormSubmit(hCtrl,
FormName)
Submits the form
QHTM_FormSetSubmitCallback(hCtrl,
Fun)
Set the function to call when submitting a form via POST
QHTM_GetDrawnSize( hCtrl,
ByRef w,
ByRef h)
Get the width and height of the HTML
QHTM_GetHTMLHeight(DC,
HTML,
Width)
Given a width determine the height of some HTML.
QHTM_GetHTML(hCtrl)
Return HTML rendered by the control
QHTM_GotoLink(hCtrl,
LinkName)
Force the HTML control to scroll to a named linked within a document.
QHTM_Init(DllPath = "qhtm.dll")
Initialise the QHTM module.
QHTM_LoadFromFile(hCtrl,
FileName)
Load HTML into QHTM passing a valid filename.
QHTM_LoadFromResource(hCtrl,  
Name,  
Resource = "")
Load HTML into QHTM from a resource
QHTM_MsgBox(HTML,  
Caption = "",
Type = "",
HGui =  0)
MsgBox replacement
QHTM_PrintCreateContext()
Create and return a print context.
QHTM_PrintDestroyContext(Context)
Destroy a valid QHTMCONTEXT.
QHTM_PrintSetText(Context,
HTML)
Set the HTML for the given print context.
QHTM_PrintSetTextFile(Context,
FileName)
Set the HTML for the given print context using a file.
QHTM_PrintLayout(Context,
DC,
PRECT)
Layout the HTML, using the HDC passed, to determine the number of pages.
QHTM_PrintPage(Context,
DC,
PageNum,
PRECT)
Print a page
QHTM_PrintGetHTMLHeight(DC,  
HTML,  
PrintWidth,  
ZoomLevel = 2)
Given a fixed width it returns the rendered height of the HTML.
QHTM_RenderHTML(DC,
HTML,
Width)
Render HTML onto a device context.
QHTM_RenderHTMLRect(DC,
HTML,
PRECT)
Render HTML onto a device context and confined within a rectangle.
QHTM_SetHTMLButton(hButton,  
Adjust = false)
Change a button so that it can contain HTML as it’s text instead of plain text.
QHTM_SetHTMLListbox(hListbox,  
Adjust =  true)
Change a listbox so that it’s items can use HTML instead of plain text.
QHTM_ShowScrollbars(hCtrl,
bShow)
Set whether or not QHTM will display scrollbars.
QHTM_Zoom(hCtrl,  
Level = 2)
Zoom the HTML in or out
Close