Rich Static Text Control using a Small Markup Language

Simple dialog using CSMLStatic

Environment: VC6 SP5, Win9x, WinNT, Win2000, WinXP


Recently, I needed an easy way to provide information on dialogs and popup information boxes to users. While a static text control could be used, I wanted to present this information in a formatted manner. I wanted to include text justification, different fonts, and styles to give the information a little more pizazz. While I could have easily created this information in RTF (rich text format) and inserted it into a rich edit control, I wanted something a little simpler to deal with in terms of creating the text and displaying it to the user.

After deciding exactly what I wanted, I implemented the CSMLDoc and CSMLStatic classes. CSMLDoc is a simple standalone class used for parsing and storing documents that use an "HTML like" markup language called SML (Small Markup Language). CSMLStatic is a CRichEditCtrl derived class that handles the display of formatted text while preventing any user action with the document (except for scrolling through large documents such as an EULA).

Since the CSMLStatic control maintains it's own CSMLDoc object, the CSMLStatic class is the only item of interest (although you might want to look at CSMLDoc for your own purposes). The CSMLStatic class works on both a CSMLDoc as well as plain text and allows both types of text to be provided through both constructors and methods.

Example of an SML document

Since the source code archive contains a help document explaining how SML works, I will only touch upon a few of the features here.

SML works on the basis of text groups. A text group is everything between break (<br>) formatting tags. Every time a break formatting tag is encountered a new text group is created. When a new text group is started, it inherits all of the styling attributes the previous group had. This includes, but it not limited to typeface, bold or italic styles, point size, justification and color. One special thing to note when dealing with text groups; whenever one of the justification tags (<center>, <right>, <left>) are encountered, the last one used in the text group is the ONLY one applied to that text group.

The following example was used in the dialog pictured above:

  <body face=DEFAULT_GUI_FONT bgcolor=COLOR_BTNFACE>
  <h4 color="800000"><u>Server Information</u></h>
  <b><u>User Information:</u></b>
  This is where you will enter your real name, email
  address, and other user identifiable information.
  <b><u>News Server:</u></b>
  This is where you enter the information about your
  Usenet news server.<br>
  <b><u>Email Server:</u></b>
  If you wish to reply to usenet posters via email,
  information about your
  outgoing SMTP e-mail server is required. This is
  where that information
  is entered.

The <body> command tag is used to indicate the entire body of the text. Everything that calls inside of the <body> tag will be used in the document. All other text that falls outside of this tag is considered to be a comment.

The <font> command tag is used to indicate a change in the typeface for a block of text. When the <font> tag is applied, all text between <font> and </font> will be displayed in the specified font and style attributes.

<center> and </center> : Begin and end center justification.

<left> and </left> : Begin and end left justification.

<right> and </right> : Begin and end right justification.

<b> and </b> : Begin and end bold style formatting.

<u> and </u> : Begin and end underline style formatting.

<i> and </i> : Begin and end italic style formatting.

<br> : Begin a new text block.

<h1>,<h2>, <h3>, <h4>, <h5>, and </h> : Header/Font point size

Constructing a CSMLStatic object

CSMLStatic provides three methods for setting the text to display:

  • BOOL SetSMLText(UINT nID);
    This method accepts an SML formatted document in the form of a resource ID. The resource MUST be created with the custom type "SMLDOC" or the CSMLDoc manager will not be able to locate it.
  • BOOL SetSMLText(LPCSTR stream);
    This method accepts an SML formatted document in the form of a null terminated buffer.
  • BOOL SetPlainText(LPCSTR lpszText);
    This method accepts a buffer containing plain text. No parsing is done on text of this type.
To create a CSMLStatic object, follow these steps:
  • Create a resource of type "SMLDOC" and insert the example code.
  • Create a dialog containing a rich edit control.
  • Using the class wizard, create a CDialog derived class that is associated with the dialog.
  • Using the class wizard, associate a variable of type CRichEditCtrl with the rich edit control in the dialog and name is m_SMLText.
  • In the dialog class, change the CRichEditCtrl to a CSMLStatic class and make sure the SMLStatic.h file is included.
  • Using the class wizard, add a handler for the WM_INITDIALOG message.
  • In the OnInitDialog() method, add the following line
    Make sure you change resID to the ID of the SMLDOC resource you created.
That's it, you're done!


Download source - 45Kb


  • Veswignee saphestanty Atterbarcarty 5249090

    Posted by lorneMory on 05/17/2013 10:56pm

    hobanomneda mulberry outlet uk Mardintirty Sneak A Peek At THIS Web-Site Tusbourbdus

  • wheloltabotly PumeSonee Phobereurce 6537807

    Posted by TizefaTaNaday on 05/17/2013 10:44pm

    Stonodoky michael Kors Handbags irriltexy Why Not Try HERE aritlytor

  • wheloltabotly PumeSonee Phobereurce 6434365

    Posted by TizefaTaNaday on 05/17/2013 08:16pm

    extetaVon insanity workout download free hignaranine Click Here CreeteSteby

  • Veswignee saphestanty Atterbarcarty 2149378

    Posted by lorneMory on 05/17/2013 08:16pm

    Inquigiggibug louis vuitton saks Draliaeviff Try THIS Web-site icelstism

  • wheloltabotly PumeSonee Phobereurce 1877023

    Posted by TizefaTaNaday on 05/10/2013 01:55am

    Infundado Louis Vuitton Store hignaranine Why Not Try these out CreeteSteby

  • wheloltabotly PumeSonee Phobereurce 4077414

    Posted by TizefaTaNaday on 05/08/2013 03:36am

    mizWoottsig Balenciaga City Grogratanow outlet burberry fearielveCaft

  • wheloltabotly PumeSonee Phobereurce 967773

    Posted by TizefaTaNaday on 05/07/2013 09:19pm

    smereneutrape Louis Vuitton Suisse Shuhinjubcono louis vuitton bindi ebay Irrifsirrasia

  • wheloltabotly PumeSonee Phobereurce 358063

    Posted by TizefaTaNaday on 05/07/2013 08:45pm

    extetaVon louis vuitton wristlet hignaranine lv shop thailand CreeteSteby

  • wheloltabotly PumeSonee Phobereurce 5395923

    Posted by TizefaTaNaday on 05/07/2013 08:41pm

    Tweteliangata Michael Kors Handbags hignaranine Visit This Website CreeteSteby

  • wheloltabotly PumeSonee Phobereurce 9662239

    Posted by TizefaTaNaday on 05/07/2013 08:38pm

    NeeseVAKseind louis vuitton change and key holder effefficamn louis vuitton mr hudson shoes for sale Smeapseestamn

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date