XP Style CColorControl Class with Themed Gradient Buttons

CColorControl

This article describes a set of control-derived classes for a colorful presentation by using XP-styled hottracked controls with themed gradient buttons. Gives your edit boxes and buttons a nice look and feel both in XP and 2K

This work is partly based on the articles "XP Style CBitmapButton (CHoverBitmapButton)" by Rail Jon Rogut and "Color Controls" by Paul J. Weiss. Credits to you both.

Note that the orginal versions of the control-derived classes were written by Paul J. Weiss. Because the application I wrote this for is intended to run on touchscreen systems, I focused mainly on the base class CColorControl, the CEdit derived CColorEdit, and, most of all, on the CButton-derived CColorButton. These classes have been completly rewritten whereas the CColorStatic and CColorComboBox classes consist of the original work by Paul. I kept them here in case anyone wants to make an effort. Don't expect them to work as they are (no offense, Paul).

Usage

  • Runs on Windows 2000 (classic mode only; see sample screendump) and Windows XP
  • CColorButton uses Uxtheme.h and tmschema.h (and corresponding libraries) for visual styling. Have your project include the path to these files (found in the SDK)
  • CColorButton uses GDI+ for drawing. gdiplus.dll must be present in targeted systems. Refer to SDK
  • Add theme.cpp and ColorControl.cpp to your project
  • Include ColorControl.h where you need it
  • Add CButton and CEdit controls to your dialogtemplate with desired style (disabled, readonly, and so forth)
  • Create control variables for each control of type CColorButton or CColorEdit
  • Compile and run

Common Functions

void CColorControl::SetColors (const COLORREF FGColor,
                               const COLORREF BGColor,
                               const COLORREF HotFGColor,
                               const COLORREF HotBGColor);
void CColorControl::SetDisabledColors (const COLORREF
                    DisabledFGColor = RGB_GRAYTEXT,
                    const COLORREF DisabledBGColor = RGB_BTNFACE);
void CColorControl::SetColorBg (COLORREF clr);
void CColorControl::SetColorFg (COLORREF clr);
void CColorControl::SetColorBgHot (COLORREF clr);
void CColorControl::SetColorFgHot (COLORREF clr);
void CColorControl::SetColorBgDisabled (COLORREF clr);
void CColorControl::SetColorFgDisabled (COLORREF clr);
void CColorControl::SetRolloverDelay (UINT mSeconds);
void CColorControl::EnableHot (bool bEnable};    // turns hottracking
                                                 // on/off

CColorButton Functions

void EnableXP(bool bEnable);    // turns XP-style (if present on
                                // system) on/off
void SetGradientColors(BYTE alphaUpper,    COLORREF rgbUpper,
                       BYTE alphaLower,    COLORREF rgbLower,
                       BYTE alphaLowerHot, COLORREF rgbLowerHot);

Don't hesitate to improve or change whatever you feel like and post it back. I'm all for perfection!

Good luck.

Anders



About the Author

Anders Sandberg

C/C++ Developer mainly focused at real-time industrial systems. http://conceptcoding.se

Downloads

Comments

  • mouse pointer area is not re-painted

    Posted by ohlik on 10/06/2004 10:38pm

    I use the windows 2000. When mouse pointer is on the botton, mouse pointer area is not re-painted.

    • Sample prg for vc6.0 reqd

      Posted by danandu on 10/19/2007 01:40am

      I am using VC 6.0. When i tried using a project converter to convert this 7.0 project to 6.0 i am facing a lot of errors like some header files are not found. If you provide 6.0 sample then it will help me.

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

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Corporate e-Learning technology has a long and diverse pedigree. As far back as the 1980s, companies were adopting computer-based training to supplement traditional classroom activities. More recently, rich web-based applications have added streaming audio and video, real-time collaboration and other new tools to the e-Learning mix. At the same time, the growing availability of informal learning tools--a category that includes everything from web searches to social media posts--are having a major impact on …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds