Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CPPHtmlStatic v1.2

0.00/5 (No votes)
18 May 2012 11  
A control based on CStatic for displaying HTML-like text formatting elements.

Contents

Features

  • Built-in HTML-lite language for a static
  • Built-in support for CSS styles  
  • Support for any size icons (max. 256 colors)
  • Support for bitmaps
  • Support for ImageList
  • Load icons, bitmaps and strings from resources, DLLs or files
  • Support standard and extend styles of the static
  • Support for gradient shadow for the images
  • Support for applies miscellaneous effects over the any images (lighten, darken, grayed)
  • Support for hyperlinks
  • Support for hot areas
  • Support for tables
  • Extended <br> and <t> tags
  • Support for an animation
  • Full source code included!

How to integrate CPPHtmlStatic in your application

To integrate HTML drawer in your application you should add next files to your project:

  • PPHtmlStatic.h
  • PPHtmlStatic.cpp
  • PPHtmlDrawer.h
  • PPHtmlDrawer.cpp
  • PPDrawManager.h
  • PPDrawManager.cpp
  • CeXDib.h, CeXDib.cpp thanks to Davide Pizzolato and Davide Calabro. This class use for extend background's effect.

Extend background effects by Davide Pizzolato and Davide Calabro become available if defined USE_SHADE:

In PPDrawManager.h

#define USE_SHADE

 

Create a CPPHtmlStatic object

Include PPHtmlDrawer.h in the header file where you want to use the CPPHtmlStatic and create a member variable:

CPPHtmlStatic m_html_static;
or
CPPHtmlStatic * m_pHtmlStatic;

Class Members

Construction

 
CPPHtmlStatic Constructs a CPPHtmlStatic object.

Operation

 
SetWindowText Specifies a text to be displayed in the static control.
SetHyperlink Specifies a hyperlink to be displayed in the static control.
SetIcon Specifies an icon to be displayed in the static control.
SetBitmap Specifies a bitmap to be displayed in the static control.
SetAnimation Specifies an animation image to be displayed in the static control.
SetImageList Specifies an item from an image list to be displayed in the static control.

Align

 
SetAlign Sets the object-alignment flags
GetAlign Gets the object-alignment flags.

Drawing

 
SetImageZoom Sets the zoom factor for an image
SetFrameRate Sets the new frame rate for the animation.
ClearFrameRate Sets the new frame rate for the animation.
SetCallbackHyperlink Sets the callback messages from the control to the parent window by clicks a hyperlink.
SetFont Sets the window's current font to the specified font.
GetFont Gets the current font for this window.
SetTextColor Sets the text color.
SetBkColor Sets the current background color.
SetBkMode Sets the background mode.
SetHyperlinkStyle Sets the style of the hyperlink.

Borders

 
SetRgn Sets a region
SetRectRgn Creates and sets a rectangle region
SetRoundRectRgn Creates and sets a rounded rectangle region
SetBorder Sets a static's border

Version

 
GetVersionI Get CPPHtmlStatic version
GetVersionC Get CPPHtmlStatic version

 

CPPHtmlStatic::CPPHtmlStatic

CPPHtmlStatic ();

Remarks
Constructs a CPPHtmlStatic object.

Example

// Create a static object on the stack.
CHtmlStatic m_HtmlStatic; 
// Create a static object on the heap. 
CHtmlStatic* m_pHtmlStatic = new CHtmlStatic; 

CPPHtmlStatic Overview | Class Members

 

CPPHtmlStatic::SetWindowText

void SetWindowText(LPCTSTR lpszText);

Parameters

  • lpszText - Specifies the text to place in the control. If NULL , no text will be visible. This text may be a HTML string.

Remarks
This method sets the static title to the specified text. This method causes a WM_SETTEXT message to be sent to this window. Text may be a HTML string like this:

<h2>CPPHtmlStatic</h2><br><hr color=blue><br>

CPPHtmlStatic Overview | Class Members

 

CPPHtmlStatic::SetHyperlink

void SetHyperlink(LPCTSTR lpszText, LPCTSTR lpszUrl, BOOL bParentNotify /* = FALSE */);

Parameters

  • lpszText - Specifies the visible text for a hyperlink. Can't be NULL.
  • lpszUrl - Specifies the target URL. Can't be NULL.
  • bParentNotify - If TRUE will be create a hyperlink for send message to the parent.

Remarks
Call this method to create an hyperlink control.

Example

// Create a hyperlink control for open WWW link.
m_html.SetHyperlink("Goto the Codeproject", 
 "http://www.codeproject.com"); 
// Create a hyperlink control to send a mail to me. 
m_html.SetHyperlink("Send mail to me", 
 "mailto:pustovoyt@mail.ru");
// Create a hyperlink control to send a message to 
 //the parent with label
 "click no.1". 
m_html.SetHyperlink("Notify a parent", "click no.1", 
 TRUE);

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic:SetIcon

void SetIcon(DWORD dwIdIcon, LPSIZE lpSize /* = NULL */);
void SetIcon(HICON hIcon);

Parameters

  • dwIdIcon - ID number of the icon resource to be drawn in the static control.
  • lpSize - A size of the loading icon.
  • hIcon - Handle of the icon to be drawn in the static control.

Remarks
Call this member function to associate a new icon image with the static control. The icon will be automatically drawn in the static control.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetBitmap

void SetBitmap(DWORD dwIdBitmap, COLORREF clrMask /*= RGB(255, 0, 255)*/);
void SetBitmap(HBITMAP hBitmap, COLORREF clrMask /*= RGB(255, 0, 255)*/);

Parameters

  • dwIdBitmap - ID number of the bitmap resource to be drawn in the static control.
  • hBitmap - Handle of the bitmap to be drawn in the static control.
  • clrMask - A transparent color on the bitmap. -1 if not transparent color present

Remarks
Call this member function to associate a new bitmap with the static control. The bitmap will be automatically drawn in the static control.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetAnimation

void SetAnimation(DWORD dwIdBitmap, LPSIZE lpSizeItem, COLORREF clrMask /*= RGB(255, 0, 255)*/);
void SetAnimation(HBITMAP hBitmap, LPSIZE lpSizeItem, COLORREF clrMask /*= RGB(255, 0, 255)*/);

Parameters

  • dwIdBitmap - ID number of the bitmap resource with image list.
  • hBitmap - Handle of the bitmap with image list.
  • clrMask - A transparent color on the bitmap. -1 if not transparent color present.
  • lpSizeItem - Dimensions of each image.

Remarks
Call this method to draw an image list as animation.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetImageList

void SetImageList(DWORD dwIdBitmap, DWORD dwIndex, LPSIZE lpSizeItem, COLORREF clrMask /*= RGB(255, 0, 255)*/);
void SetImageList(HBITMAP hBitmap, DWORD dwIndex, LPSIZE lpSizeItem, COLORREF clrMask /*= RGB(255, 0, 255)*/);

Parameters

  • dwIdBitmap - ID number of the bitmap resource with image list.
  • hBitmap - Handle of the bitmap with image list.
  • clrMask - A transparent color on the bitmap. -1 if not transparent color present.
  • lpSizeItem - Dimensions of each image.
  • dwIndex - Zero-based index of the image .

Remarks

Call this member function to associate an image from an image list with the static control.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetAlign

void SetAlign(DWORD dwAlign /*= PPHTMLSTATIC_ALIGN_DEFAULT*/);

Parameters

  • dwAlign - Specifies object-alignment flags. The first category affects object alignment in the x-direction:
    PPHTMLSTATIC_ALIGN_DEFAULT - Use an alignment from CStatic styles (SS_CENTER, SS_LEFT, SS_RIGHT, SS_CENTERIMAGE)
    PPHTMLSTATIC_ALIGN_LEFT
    PPHTMLSTATIC_ALIGN_RIGHT
    PPHTMLSTATIC_ALIGN_CENTER
    PPHTMLSTATIC_ALIGN_TOP
    PPHTMLSTATIC_ALIGN_BOTTOM
    PPHTMLSTATIC_ALIGN_VCENTER

Remarks
Sets the object-alignment flags.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::GetAlign

DWORD GetAlign();

Return value

The status of the object-alignment flags. See the SetAlign function for the list of the available flags

Remarks
Retrieves the status of the object-alignment flags.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetImageZoom

void SetImageZoom(int nWidthPercent /*= 100*/, int nHeightPercent /*= 100*/);
void SetImageZoom(int nPercent /*= 100*/);

Remarks
Sets the zoom factor (in percents) for an image.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetFrameRate

void SetFrameRate(DWORD dwFrameRate /*=500*/);

Parameters

  • dwFrameRate - Specified a time-out value between current and next displayed bitmap.

Remarks
Sets the new frame rate for the animation. For the CPPHtmlStaticl class the frame rate means a time-out period in milliseconds between current and next bitmap instead of number of frames per second. The default value is 500 milliseconds.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::ClearFrameRate

void ClearFrameRate();

Remarks
Kills an animation timer.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetCallbackHyperlink

void SetCallbackHyperlink(UINT nMessage, LPARAM lParam /* = 0 */);

Parameters

  • nMessage - Specifies the message to be sent.
  • lParam - Specifies additional user-defined information

Remarks

This method sets the callback messages from the control to the parent window if user clicks a hyperlink with msg parameter.

Format a callback message:
    Msg - Specified ID message
    wParam - Pointer to the string specified as msg 
     parameter of the <a href="#A_Tag"><a></a> tag.
    lParam - Additional user-defined value

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetFont

void SetFont(CFont* pFont, BOOL bRedraw /*= TRUE*/);

Parameters

  • pFont - Specifies the new font.
  • bRedraw - If TRUE, redraw the CPPHtmlStatic object

Remarks

Sets the window's current font to the specified font. If bRedraw is TRUE , the window will also be redrawn.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::GetFont

CFont* GetFont();

Return value

A pointer to a CFont that contains the current font. The pointer may be temporary and should not be stored for later use.

Remarks

Gets the current font for this window.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetTextColor

void SetTextColor(COLORREF clrText);

Parameters

  • clrText - Specifies the color of the text as an RGB color value.

Remarks

Sets the text color to the specified color.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetBkColor

void SetBkColor(COLORREF clrBk);

Parameters

  • clrBk - Specifies the new background color.

Remarks

Sets the current background color to the specified color.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetBkMode

void SetBkMode(int nBkMode /*= TRANSPARENT*/);

Parameters

  • nBkMode - Specifies the mode to be set. This parameter can be either of the following values:
    • OPAQUE Background is filled with the current background color before the text is drawn.
    • TRANSPARENT Background is not changed before drawing. This is the default background mode.

Remarks

Sets the background mode. The background mode defines whether the system removes existing background colors on the drawing surface before drawing text.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetHyperlinkStyle

void SetHyperlinkStyle(COLORREF clrOrg, BOOL bOrgUnderline, COLORREF clrHover, BOOL bHoverUnderline);

Parameters

  • clrOrg - Specifies the color of the hyperlink text when mouse isn't over the link.
  • bOrgUnderline - Specifies the underline style of the hyperlink text when mouse isn't over the link.
  • clrHover - Specifies the color of the hyperlink text when mouse is over the link.
  • bHoverUnderline - Specifies the underline style of the hyperlink text when mouse is over the link.

Remarks

Specified the colors and underline styles for normal and hover mode of the hyperlink.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetRgn

void SetRgn(HRGN hRgn = NULL);

Parameters

  • hRgn - Handle to the region to be selected. NULL if any region must be delete.

Remarks

Specified a region as the current clipping region for the static control.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetRectRgn

void SetRectRgn();

Remarks

Creates a rectangular region by client area of the static control and select him as the current clipping region.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetRoundRectRgn

void SetRoundRectRgn(int nWidth, int nHeight);

Parameters

  • nWidth - Specifies the width of the ellipse used to create the rounded corners.
  • nHeight - Specifies the height of the ellipse used to create the rounded corners.

Remarks

Creates a rectangular region with rounded corners by client area of the static control and select him as the current clipping region.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::SetBorder

void SetBorder(COLORREF color, int nWidth = 1, int nHeight = 1);
void SetBorder(HBRUSH hbr, int nWidth = 1, int nHeight = 1);

Parameters

  • color - Specifies the color to create a solid brush.
  • hbr - Handle to the brush to be used to draw the border.
  • nWidth - Specifies the width, in logical units, of vertical brush strokes.
  • nHeight - Specifies the height, in logical units, of horizontal brush strokes.

Remarks

Draws a border around the specified region by using the specified brush.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::GetVersionI

short GetVersionI()

Return Value

Number version of CPPHtmlStatic.

Remarks

Returns the CPPHtmlStatic version as a short number. Divide by 10 to get actual version.

CPPHtmlStatic Overview | Class Members

CPPHtmlStatic::GetVersionC

LPCTSTR GetVersionC()

Return Value

Number version of CPPHtmlStatic as string.

Remarks

Returns the CPPHtmlStatic version as a string.

CPPHtmlStatic Overview | Class Members

History

09 May 2004 First release
25 May 2004

Released version 1.1
- Added SetTextColor, SetBkColor and SetBkMode methods;
- Documented a SetHyperlinkStyle method;
- Added a ClearFrameRate method (thanks to Steve Mayfield);
- Fixed the minor errors with animation (thanks to Steve Mayfield);
- Fixed a dirty multi-drawn
- Enable state of the control wasn't initialized right

25 September 2004

Released version 1.2
- Support a text wrapping;
- Added support for the common character entities;
- Added a <justify> tag;
- Support a disabled draw in the tables;
- Fixed minor errors of drawing table's cells;
- Added a gradient filling of the static;
- Added some styles of the static borders  

18 May 2012

Added documentation for the simple HTML language. This HTML can use with CPPStatic and CPPTooltip controls.

Contacting the Author

You are encouraged to use this class everywhere you want; there is no fee required for CPPHtmlStatic. Freely add modifications and/or fix bugs, but please, send any of these to me!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here