Rich Static Text Control using a Small Markup Language


Simple dialog using CSMLStatic

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

Introduction

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>
  <center>
  <h4 color="800000"><u>Server Information</u></h>
  </center>
  <br>
  
  <br>
  <b><u>User Information:</u></b>
  <br><over>
  This is where you will enter your real name, email
  address, and other user identifiable information.
  </over><br>
  
  <br>
  <b><u>News Server:</u></b>
  <br>
  This is where you enter the information about your
  Usenet news server.<br>
  
  <br>
  <b><u>Email Server:</u></b>
  <br>
  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.
  </body>

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
    	m_SMLText.SetSMLText(resID);
    Make sure you change resID to the ID of the SMLDOC resource you created.
That's it, you're done!

Downloads

Download source - 45Kb


Comments

  • 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

    Reply
  • wheloltabotly PumeSonee Phobereurce 6537807

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

    Stonodoky michael Kors Handbags irriltexy Why Not Try HERE aritlytor

    Reply
  • wheloltabotly PumeSonee Phobereurce 6434365

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

    extetaVon insanity workout download free hignaranine Click Here CreeteSteby

    Reply
  • Veswignee saphestanty Atterbarcarty 2149378

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

    Inquigiggibug louis vuitton saks Draliaeviff Try THIS Web-site icelstism

    Reply
  • wheloltabotly PumeSonee Phobereurce 1877023

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

    Infundado Louis Vuitton Store hignaranine Why Not Try these out CreeteSteby

    Reply
  • wheloltabotly PumeSonee Phobereurce 4077414

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

    mizWoottsig Balenciaga City Grogratanow outlet burberry fearielveCaft

    Reply
  • wheloltabotly PumeSonee Phobereurce 967773

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

    smereneutrape Louis Vuitton Suisse Shuhinjubcono louis vuitton bindi ebay Irrifsirrasia

    Reply
  • wheloltabotly PumeSonee Phobereurce 358063

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

    extetaVon louis vuitton wristlet hignaranine lv shop thailand CreeteSteby

    Reply
  • wheloltabotly PumeSonee Phobereurce 5395923

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

    Tweteliangata Michael Kors Handbags hignaranine Visit This Website CreeteSteby

    Reply
  • 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

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

Top White Papers and Webcasts

  • Live Event Date: September 17, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

  • Live Event Date: September 16, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you starting an on-premise-to-cloud data migration project? Have you thought about how much space you might need for your online platform or how to handle data that might be related to users who no longer exist? If these questions or any other concerns have been plaguing you about your migration project, check out this eSeminar. Join our speakers Betsy Bilhorn, VP, Product Management at Scribe, Mike Virnig, PowerSucess Manager and Michele …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds