MiniHTML control

MiniHTML control

This article was submitted .

Here is yet another label control with text formatting. This time it's on pure GDI calls, since most of the other label controls I have are RTF based. Using pure GDI calls have the advantage that you don't have to worry about which version of RTF is installed on the machine, and the drawing routine can be re-use for other components without including a clumsy RTF child-window to get decent text formatting.

The control supports simple HTML, known as mini html. That's just the basic HTML text formatting tags. It also includes word-wrapping for multi-line support.

Internally the control builds a list of actions that describe how to paint the text. This allows for the control to only parse the HTML text once and quickly repaint the control when needed.

HTML tag support

The following tags are supported:
The bold text format.

Formats text in italics.

Prints underlined text.

The font tag with several attributes, such as FACE="xyz", SIZE=n and COLOR="#rrggbb".

A single line-break. Note that CR LF combinations are ignored.

A line-breaking text strip. Supports the following attribute: ALIGN="xyz".

How to use it

To use it, place a STATIC control (label) on your dialog.
Add a member variable to your dialog implementation file...
CMiniHtmlCtrl m_ctrlLabel
In the OnInitDialog() event handler, add the following lines:
LRESULT OnInitDialog(UINT /*uMsg*/, 
                     WPARAM /*wParam*/, 
                     LPARAM /*lParam*/, 
                     BOOL& /*bHandled*/)
  m_ctrlLabel.SetWindowText("html stuff goes here...");

Source Code Dependencies

Microsoft Visual C++ 6.0
Microsoft WTL 7.0 Library

See Also

A RTF based label control.

Download Files

DownloadSource Code (6 Kb)

To the top