![]() |
Desktop Development »
Static & Panel Controls »
General
Intermediate
License: The Code Project Open License (CPOL)
CGroupLineBy Warren StevensCStatic enhancement that adds a trailing horizontal line, and supports WinXP themes. |
VC7.1, Windows, MFC, VS.NET2003, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||
This article presents CGroupLine, a class derived from CStatic that adds a horizontal line to your static text, and includes support for XP Themes. The control looks similar to the controls used in Office 2003 (see Tools->Options in Word or Excel).

The control is called GroupLine because it is very similar to the standard GroupBox. The GroupLine control looks very much like the top edge of a GroupBox, and the purpose of both controls is to present dialog controls in logical groups. The difference is that the GroupLine is only the top Line of the GroupBox. GroupLine provides a nice way to bundle controls into logical groups (the whole point of a group control), but without the downside of the GroupBox (i.e. wasting valuable dialog real estate, on the left, right and bottom).
The image helps to demonstrate the main features of CGroupLine:
GroupBoxes with themes are drawn the same way when enabled as when they are disabled. This seemed like an odd behaviour, so CGroupLine draws the disabled state with grayed-out text. Using the control is fairly simple. Essentially, you just associate a static text control with a member variable, and change the type of the member variable from CStatic to CGroupLine. The public portion of the class is listed here:
class CGroupLine : public CStatic { public: // controls use of themes (aka visual styles) enum eThemeControl { eThemeAutomatic, // checks if themes are // used for the app eThemeOff, // no use of themes eThemeOn, // use themes }; // controls how the disabled state is drawn enum eDisabledThemeStyle { eGrayIfDisabled, // draws disabled state with // typical disabled gray text eSameAsEnabled, // draws disabled state the same // as the enabled state (default // for XP Themed GroupBoxes) }; CGroupLine(eThemeControl useTheme = eThemeAutomatic, eDisabledThemeStyle disabledThemeStyle = eGrayIfDisabled); virtual ~CGroupLine(); void SetUseTheme(eThemeControl useTheme); void SetDisabledThemeStyle( eDisabledThemeStyle disabledThemeStyle);
A few notes about the code:
CGroupLine class is derived from CStatic. To use the control, you just add a regular Static Text control to your dialog, and assign it an ID. Associate this control with a member variable (e.g. using the Add Member Variable Wizard), and change the type of the member variable from CStatic to CGroupLine. GroupBoxes with themes are drawn the same way when enabled as when they are disabled. This seemed like an odd behaviour, so CGroupLine draws the disabled state with grayed-out text. To change this behaviour back to the default (i.e. drawing the enable and disabled state the same way) use the SetDisabledThemeStyle function or the optional parameter to the constructor. SetUseTheme function or the optional parameter to the constructor. The executable provided in the demo needs a manifest file to be present in order to draw the controls with the XP theme style. This following article explains how to embed the XP manifest in your executable, rather than providing a separate manifest file: Add Windows XP Theme Style to your current projects by Jiang Hong.
The method explained in that article works with this project, but I used a separate manifest file so it would be easy to see the effect of adding or removing the file (i.e. to see the control draw with the themes on or off without having to rebuild the project).
The theme drawing is provided by UxTheme.Dll, which is provided only on Windows XP or later. You may have to delay-load UxTheme.Dll, if you want your application to run on versions of Windows prior to XP (e.g. Windows 2000).
To delay-load a DLL in Visual Studio 2003 (for other compiler versions, refer to the help):
The code in this article includes a function BOOL CGroupLine::IsThemed() that is taken from Nishant Sivakumar's article: How to accurately detect if an application is theme-enabled.
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 18 Nov 2008 Editor: Sean Ewington |
Copyright 2005 by Warren Stevens Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |