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
- 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).
- Add these two files to your project:
- Add #include "HelpStatic.h" to your dialogs header file.
- Declare an instance of
CHelpStatic for each inserted control which you have created in the dialog-resource.
- 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
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
- 18th May, 2011: First released
- 20th May, 2011: Updated article