Click here to Skip to main content
13,402,312 members (56,938 online)
Click here to Skip to main content
Add your own
alternative version


13 bookmarked
Posted 25 May 2011

A Comfortable Custom Text-control for Generating helptext in Dialogs

, 25 May 2011
Rate this:
Please Sign up or sign in to vote.
Extends the CStatic with image, frame, shadow and using individual font


For a project of my own, I was looking for a dialog-control which I can use in the project's dialogs for showing helptexts above of the dialog. Because I found no fitting control, I wrote it by myself, and now I want to share it with the community. If you want to see the control in action, download the demo-project. If you want to use the control, download the source-code of the new class.



CHelpStatic is derived from CStatic and extends its appearance with drawing an image on the left side, custom font, a frame, backgroundcolour/textcolour and a shadow. If you are using an image, the image is automatically sized to fit into the size of the control.

You can also define a number of pixels for the distance between the text and the frame-sides. This makes the helptext better for reading.

The control-class also can be used only as a color-static-control by only setting the text-colour.

Using the Code

The following functions are available. Note that you don't have to use any of them, but if used, the appearance will extend.

  • void SetColorBack(COLORREF rgb);

    Sets the colour for the background. If not used, windows-standard colour (COLOR_3DFACE) for dialogs is used.

  • void SetColorText(COLORREF rgb);

    Sets the colour of the text. If not used, windows-standard colour (COLOR_BTNTEXT) for buttons is used.

  • void SetFont(LPCTSTR czFace, int iSize=10);

    Sets the face and size of the desired font. If not used, windows standard font (DEFAULT_GUI_FONT) is used.

  • void SetMargin(int iPixel);

    Sets the number of pixels you want between the frame-sides and the drawing text. If not used, no distance is given. Set it to 0 if you want to disable the margin.

  • void SetText(LPCTSTR czText);

    Sets the text for the control.

  • void LoadPicture(int iResID);

    Loads an image from the resource and activates the drawing of the image on the left side of control. The text of the control is automatically shifted to the right side of the image.

  • void EnableFrame(BOOL bEnable,COLORREF rgb=RGB(0,0,0));

    Enable or disables the drawing of a frame around the control. If you enable the frame, you can also define the colour of the frame.

  • void EnableShadow(BOOL bEnable=TRUE);

    Enables or disables a shadow on the bottom and right side of the control. The shadow will be drawn into the size of the control like you defined in the resource. This means, that, if a shadow is used, the extend of the whole control is the same as without a shadow.

For a detailed description of the functions, take a look at the remarks about the functions in the source-code.

How to Implement

  1. In your dialog, create a static text-control-element for each helptext you want and position it on the desired place (for example, on the top of your dialog).
  2. Add these two files to your project:
    • HelpStatic.cpp
    • HelpStatic.h
  3. Add #include "HelpStatic.h" to your dialogs header file.
  4. Declare an instance of CHelpStatic for each inserted control which you have created in the dialog-resource.


    CHelpStatic m_help;
  5. In your OnInitDialog(), add a SubclassDlgItem() for each CHelpStatic member variable.



    Alternatively, you can use the wizard in VS to add a member-variable for the static-ctrl. In the field for the variable-type, type "CHelpStatic". The wizard then creates an entry in DoDataExchange().

  6. In OnInitDialog(), initialize every help-control using one or a number of the above mentioned functions.



If you don't use any of these functions, the control is shown with default settings (like a normal CStatic-object).


  • 18th May, 2011: First released
  • 20th May, 2011: Updated article


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Rob A. Fraydl
Team Leader
Austria Austria
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralOther solution Pin
JimmyO25-May-11 22:43
memberJimmyO25-May-11 22:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180218.2 | Last Updated 25 May 2011
Article Copyright 2011 by Rob A. Fraydl
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid