Click here to Skip to main content
15,888,733 members
Articles / Desktop Programming / MFC

Fancy Controls

Rate me:
Please Sign up or sign in to vote.
4.82/5 (31 votes)
23 Nov 2001CPOL14 min read 294K   9.5K   137   58
A new set of classes for a fancy look
HMXShapedDialog HMXDialog with Bitmap HMXDialog with Color
HMXShapedFormView HMXFormView with Bitmap HMXFormView with Color

Introduction

The starting question: Why VB & Delphi programmers can easily use fancy controls?

I wrote these classes because my customers was really bored interacting with the usual controls, dialogs and forms: always the same font, the same color, always rectangular shapes... and I agree.

As you know, using only the standard MFC classes, it's really hard to modify the aspect of UI, so I decided to create my own quick solution for a fancy look for all new programs. Of course, these aren't classes which you cannot live without. But, I'm sure, sometimes users believe a program is very useful if it has a colored look... [ XP teaches!? -my personal opinion- ]

Here is a description of the classes and few tips for their use.

The Classes

There are these classes in this set:

CHMXStatic replaces CStatic and gives you a better control over static text
CHMXEdit replaces CEdit improving edit box behavior
CHMXNumEdit replaces CEdit too, but it's dedicated to numerical inputs
CHMXCheckBox replaces check box class
CHMXComboBox replaces CComboBox, either drop down and drop list
CHMXListBox replaces CListBox
CHMXListCtrl replaces CListCtrl in any view
CHMXDialog a new CDialog class with colors and images as background
CHMXShapedDialog Are you bored using rectangular dialogs?
CHMXFormView replaces CFormView. Your MDI applications will never be the same.
CHMXShapedFormView replaces CFormView. Your MDI applications with a new look.

Someone could ask me: "What about radio buttons? And buttons?".

My answer: "Sorry, I hare radio buttons, thus... Buttons: I can suggest Davide Calabro's CButtonST v3.4 (MFC Flat buttons) & CShadeButtonST or Davide Pizzolato's CxSkinButton & CxShadeButton... [ Italians do buttons better :)) ]".

If you just have your preferred CMySpecialEdit (derived from CEdit class) and want to integrate its features with CHMXEdit features, all you have to do is derive CHMXEdit from CMySpecialEdit instead of CEdit. In most cases, this could be enough.

How to Use CHMXStatic

This is the simplest class of the group. It allows you to have a better control over a static text.

To use a control as CHMXStatic, you have to declare it as CHMXStatic instead of CStatic. To do so, search the declaration of the control you created and replace CStatic with CHMXStatic.

Don't forget to add...

C++
#include "HMXControls.h"

...before its use.

Using this control, you can:

Set text color SetTextClr(clr) clr represents the color you want to use
Get text color GetTextClr(clr) clr will keep the control text color
Set background color SetBkClr(clr) clr represents the color you want to use
Get background color GetBkClr(clr) clr will keep the control background color
Set transparency SetTransparent(bTransparent) bTransparent represents the flag for transparency; if a control is transparent, the background isn't painted
Get transparency GetTransparent(bTransparent) bTransparent will keep the transparency status
Set text font SetTextFont(nHeight, bBold, bItalic, sFaceName) nHeight, bBold, bItalic, sFaceName represent the height in point, the bold flag, the italic flag and the name of the font
Set text font SetTextFont(LogFont) LogFont represents a LOGFONT structure
Get text font GetTextFont(lpLogFont) lpLogFont represents the pointer to a LOGFONT structure
Set text font height SetTextFontHeight(nHeight) nHeight represents the height in point of the font
Set text font bold SetTextFontBold(bBold) bBold represents the flag for the bold style
Set text font italic SetTextFontItalic(bItalic) bItalic represents the flag for the italic style
Set text font face name SetTextFontFaceName(sFaceName) sFaceName represents the name of the font
Set font rotation SetFontRotation(nAngle) nAngle represents the angle of the rotation
Set tooltip text SetToolTipText(sToolTip, bActivate) sToolTip, bActivate represent the tooltip text and the activation flag
Activate tooltip ActivateToolTip(bActivate) bActivate represents the activation flag

Of course, if you're looking for a 'full of features' CStatic class, I can suggest CLabel [thanks Mr. Almond, your job is fantastic].

How to Use CHMXEdit

This class replaces CEdit class. It allows you to control the edit box appearance. As you can see, I created a particular method: EnableEditing; in this way, this kind of control acts better than CEdit with EnableWindow or SetReadOnly.

To use a control as CHMXEdit, you have to declare it as CHMXEdit instead of CEdit. To do so, refer to CHMXStatic section.

Don't forget to...

C++
#include "HMXControls.h"

...before its use.

Using this control, you can:

Set text color SetTextClr(clr) clr represents the color you want to use
Get text color GetTextClr(clr) clr will keep the control text color
Set text color focus SetTextClrFocus(clr) clr represents the color you want to use if control has focus
Get text color focus GetTextClrFocus(clr) clr will keep the control text color when the control has the focus
Set background color SetBkClr(clr) clr represents the color you want to use
Get background color GetBkClr(clr) clr will keep the control background color
Set background color focus SetBkClrFocus(clr) clr represents the color you want to use when control has focus
Get background color focus GetBkClrFocus(clr) clr will keep the control background color when control has focus
Set text font SetTextFont(nHeight, bBold, bItalic, sFaceName) nHeight, bBold, bItalic, sFaceName represent the height in point, the bold flag, the italic flag and the name of the font
Set text font SetTextFont(LogFont) LogFont represents a LOGFONT structure
Get text font GetTextFont(lpLogFont) lpLogFont represents the pointer to a LOGFONT structure
Set text font height SetTextFontHeight(nHeight) nHeight represents the height in point of the font
Set text font bold SetTextFontBold(bBold) bBold represents the flag for the bold style
Set text font italic SetTextFontItalic(bItalic) bItalic represents the flag for the italic style
Set text font face name SetTextFontFaceName(sFaceName) sFaceName represents the name of the font
Set tooltip text SetToolTipText(sToolTip, bActivate) sToolTip, bActivate represent the tooltip text and the activation flag
Activate tooltip ActivateToolTip(bActivate) bActivate represents the activation flag
Enable editing EnableEditing(bEditing) bEditing represents the editing flag

How to Use CHMXNumEdit

This class depends on CHMXEdit and must be used if you have numeric input. Once created, this control allows you to type only digits, decimal separator, plus, minus and 'e'.

I implemented a solution for 'localization & decimal separator problem'. In a normal CEdit control, if you type '.' you get (of course) the dot. If you try to do the same using Calc (windows calculator) if you type '.' you get the decimal separator (as defined in Control Panel). Excel does the same. I mean it's really comfortable typing numbers using only the numpad, especially for Europeans that use the comma as decimal separator. This class allows you to have this useful feature. To complete the operation, you have to use...

C++
setlocale( LC_ALL, ".OCP" );

...in this way, you inform your program to use regional settings from the control panel: every time you press '.' you'll get your own decimal separator.

To use a control as CHMXNumEdit, you have to declare it as CHMXNumEdit instead of CEdit. See previous sections.

As you know...

C++
#include "HMXControls.h"

...before its use.

It's derived from CHMXEdit so you can refer to CHMXEdit section. Using this control, you also can:

Set engineer format SetEngFormat(bEngFormat) bEngFormat represents the flag for engineer format
Get engineer format GetEngFormat(bEngFormat) bEngFormat will keep the format used

How to Use CHMXCheckBox

This class, improving the standard CButton class, allows you to control the check box appearance. To use a check box as CHMXCheckBox, you have to declare it as CHMXCheckBox instead of CButton.

Don't forget to add...

C++
#include "HMXControls.h"

...before its use.

Using this control, you can:

Set text color SetTextClr(clr) clr represents the color you want to use
Get text color GetTextClr(clr) clr will keep the control text color
Set background color SetBkClr(clr) clr represents the color you want to use
Get background color GetBkClr(clr) clr will keep the control background color
Set transparency SetTransparent(bTransparent) bTransparent represents the flag for transparency; if a control is transparent, the background isn't painted
Get transparency GetTransparent(bTransparent) bTransparent will keep the transparency status
Set text font SetTextFont(nHeight, bBold, bItalic, sFaceName) nHeight, bBold, bItalic, sFaceName represent the height in point, the bold flag, the italic flag and the name of the font
Set text font SetTextFont(LogFont) LogFont represents a LOGFONT structure
Get text font GetTextFont(lpLogFont) lpLogFont represents the pointer to a LOGFONT structure
Set text font height SetTextFontHeight(nHeight) nHeight represents the height in point of the font
Set text font bold SetTextFontBold(bBold) bBold represents the flag for the bold style
Set text font italic SetTextFontItalic(bItalic) bItalic represents the flag for the italic style
Set text font face name SetTextFontFaceName(sFaceName) sFaceName represents the name of the font
Set tooltip text SetToolTipText(sToolTip, bActivate) sToolTip, bActivate represent the tooltip text and the activation flag
Activate tooltip ActivateToolTip(bActivate) bActivate represents the activation flag
Enable editing EnableEditing(bEditing) bEditing represents the editing flag

How to Use CHMXComboBox

This class replaces CCombobox class either drop list and drop down. It allows you to control the combo box appearance. To use a control as CHMXComboBox, you have to declare it as CHMXComboBox instead of CComboBox.

Don't forget to...

C++
#include "HMXControls.h"

...before its use.

Using this control, you can:

Set text color SetTextClr(clr) clr represents the color you want to use
Get text color GetTextClr(clr) clr will keep the control text color
Set background color SetBkClr(clr) clr represents the color you want to use
Get background color GetBkClr(clr) clr will keep the control background color
Set text font SetTextFont(nHeight, bBold, bItalic, sFaceName) nHeight, bBold, bItalic, sFaceName represent the height in point, the bold flag, the italic flag and the name of the font
Set text font SetTextFont(LogFont) LogFont represents a LOGFONT structure
Get text font GetTextFont(lpLogFont) lpLogFont represents the pointer to a LOGFONT structure
Set text font height SetTextFontHeight(nHeight) nHeight represents the height in point of the font
Set text font bold SetTextFontBold(bBold) bBold represents the flag for the bold style
Set text font italic SetTextFontItalic(bItalic) bItalic represents the flag for the italic style
Set text font face name SetTextFontFaceName(sFaceName) sFaceName represents the name of the font
Set tooltip text SetToolTipText(sToolTip, bActivate) sToolTip, bActivate represent the tooltip text and the activation flag
Activate tooltip ActivateToolTip(bActivate) bActivate represents the activation flag
Enable editing EnableEditing(bEditing) bEditing represents the editing flag

How to Use CHMXListBox

If you want to use a list box and want to set font, colors and background colors, you have to use the CHMXListBox class.

Don't forget to...

C++
#include "HMXControls.h"

...before its use.

Using this control, you can:

Set text color SetTextClr(clr) clr represents the color you want to use
Get text color GetTextClr(clr) clr will keep the control text color
Set background color SetBkClr(clr) clr represents the color you want to use
Get background color GetBkClr(clr) clr will keep the control background color
Set text font SetTextFont(nHeight, bBold, bItalic, sFaceName) nHeight, bBold, bItalic, sFaceName represent the height in point, the bold flag, the italic flag and the name of the font
Set text font SetTextFont(LogFont) LogFont represents a LOGFONT structure
Get text font GetTextFont(lpLogFont) lpLogFont represents the pointer to a LOGFONT structure
Set text font height SetTextFontHeight(nHeight) nHeight represents the height in point of the font
Set text font bold SetTextFontBold(bBold) bBold represents the flag for the bold style
Set text font italic SetTextFontItalic(bItalic) bItalic represents the flag for the italic style
Set text font face name SetTextFontFaceName(sFaceName) sFaceName represents the name of the font
Set tooltip text SetToolTipText(sToolTip, bActivate) sToolTip, bActivate represent the tooltip text and the activation flag
Activate tooltip ActivateToolTip(bActivate) bActivate represents the activation flag
Enable editing EnableEditing(bEditing) bEditing represents the editing flag

How to Use CHMXListCtrl

Refers to CHMXListBox.

How to Use CHMXDialog

With this class, you can create a dialog having a colored background or a bitmap as background too. Using a BMP as background, it is possible to have the image centered, tiled or stretched.

This class allows you to:

Set background color SetBkClr(clr) clr is the color of the dialog background
Get background color GetBkClr(clr) clr will keep the dialog background color
Set background bitmap SetBitmap(sFileName, nStyle) sFileName is the file that contains the image, nStyle represents the style of the image painting method: centered, tiled or stretched
Set background bitmap SetBitmap(nResource, nStyle) nResource is the resource ID contains the image, nStyle represents the style of the image painting method

To use this dialog, you have to design your own dialog via resource editor as you normally do using Visual Studio. Remember to increase control sizes if you plan to use custom text for labels (static), check boxes and edit boxes; combo boxes increase their sizes automatically. Now, using ClassWizard, create your MyDialog.cpp & MyDialog.h (your class name could be CMyDialog). ClassWizard helps you to create variables associated to controls like m_edtText for a CEdit control, m_lblLabel for a CStatic control and so on.

In order to let CHMXDialog derived class work correctly, make the following changes:

  • Open MyDialog.h
  • Type:
    C++
    #include "HMXControls.h"
    just before the class definition,
  • Replace CDialog with CHMXDialog in class definition
  • If required, convert each control in this header file using this conversion table:
    Old New Notes
    CStatic CHMXStatic  
    CEdit CHMXEdit for alpha & numeric edit box
    CEdit CHMXNumEdit only numeric edit box
    CButton CHMXCheckBox NOT FOR BUTTON!! ONLY CHECKBOX
    CComboBox CHMXComboBox Drop Down & Drop List
    CListBox CHMXListBox  
    CListCtrl CHMXListCtrl  
  • It's necessary to override OnInitDialog in order to modify dialog & controls make-up
  • Open MyDialog.cpp
  • Make the following changes:
    Where Old New
    constructor CDialog(

    CMyDialog::IDD, pParent)

    CHMXDialog(

    CMyDialog::IDD, pParent)

    DoDataExchange CDialog::DoDataExchange(pDX); CHMXDialog::

    DoDataExchange(pDX);

    BEGIN_MESSAGE_MAP BEGIN_MESSAGE_MAP(CMyDialog, CDialog) BEGIN_MESSAGE_MAP(CMyDialog, CHMXDialog)
    OnInitDialog CDialog::OnInitDialog(); CHMXDialog::

    OnInitDialog();

How to Use CHMXShapedDialog

As the name suggests, with this class, you can create a dialog with its own shape, depending on the bitmap file selected.

This class allows you to set a bitmap as 'mask' via a method like this:

C++
SetRegionFile( sFileName, clrTransp )

where sFileName represents the file containing BMP image and clrTransp is the color that must be used as transparent color.

Important: This dialog must be without caption and border.

How to Use CHMXFormView

This class allows you to:

Set background color SetBkClr(clr) clr is the color of the dialog background
Get background color GetBkClr(clr) clr will keep the dialog background color
Set background bitmap SetBitmap(sFileName, nStyle) sFileName is the file that contains the image, nStyle represents the style of the image painting method: centered, tiled or stretched
Set background bitmap SetBitmap(nResource, nStyle) nResource is the resource ID that contains the image, nStyle represents the style of the image painting method

Using Visual Studio Resource Editor, design your own form and, via Class wizard, create your CMyFormView.

In order to let CHMXFormView derived class work correctly, make the following changes:

  • Open MyFormView.h
  • Type:
    C++
    #include "HMXControls.h"
    just before the class definition
  • Replace CFormView with CHMXFormView in class definition
  • If required, convert each control in this header file using this conversion table:
    Old New notes
    CStatic CHMXStatic  
    CEdit CHMXEdit for alpha & numeric edit box
    CEdit CHMXNumEdit only numeric edit box
    CButton CHMXCheckBox NOT FOR BUTTON!! ONLY CHECKBOX
    CComboBox CHMXComboBox Drop Down & Drop List
    CListBox CHMXListBox  
    CListCtrl CHMXListCtrl  
  • It's necessary to override OnInitalUpdate in order to modify form and controls make-up
  • Open MyFormView.cpp
  • Make the following changes:
    Where Old New
    constructor CFormView(CMyFormView::IDD) CHMXFormView(CMyFormView::IDD)
    DoDataExchange CFormView::

    DoDataExchange(pDX);

    CHMXFormView(CMyFormView::IDD)
    BEGIN_MESSAGE_MAP BEGIN_MESSAGE_MAP(CMyFormView, CFormView) BEGIN_MESSAGE_MAP(CMyFormView, CHMXFormView)
    OnInitialUpdate CFormView::

    OnInitalUpdate();

    CHMXFormView::

    OnInitalUpdate();

In method CMyFormView::OnInitialUpdate(), just before CHMXFormView::OnInitalUpdate(), I suggest to type:

C++
GetParentFrame()->RecalcLayout();
ResizeParentToFit(FALSE);

In this way, the form will have the right size.

How to Use CHMXShapedFormView

This section is a little bit tricky... if you follow these instructions, you can get the right results. Designing your own form using Resource Editor and, via Class Wizard, create your own CMyShapedFormView. Now follow these steps:

  • Open main file MyProject.h
  • Add extern CString g_sMyShapedFormViewBMPFile;
  • Add extern COLORREF g_rgbMyShapedFormViewRGBTransp;
  • Open main file MyProject.cpp
  • Type #include "HMXcontrols.h"
  • Replace RUNTIME_CLASS(CChildFrame), with RUNTIME_CLASS(CHMXChildFrame) in Document templates registrations
  • In InitInstance add g_sMyShapedFormViewBMPFile = "MyImage.BMP";
  • In InitInstance add g_rgbMyShapedFormViewRGBTransp = RGB( x, y, z);
  • Design form via Resource Editor
  • Create, using Class Wizard, the class CMyShapedFormView (derived from CFormView)
  • Open MyShapedFormView.h
  • Type #include "HMXcontrols.h"
  • Replace class CMyShapedFormView : public CFormView with class CMyShapedFormView : public CHMXShapedFormView
  • Open MyShapedFormView.cpp
  • Add CString g_sMyShapedFormViewBMPFile;
  • Add COLORREF g_rgbMyShapedFormViewRGBTransp;
  • Replace CMyShapedFormView(CMyShapedFormView::IDD ) with CMyShapedFormView(CMyShapedFormView::IDD, g_sMyShapedFormViewBMPFile, g_rgbMyShapedFormViewRGBTransp )
  • Replace CFormView::DoDataExchange(pDX) with CHMXShapedFormView::DoDataExchange(pDX)
  • Replace BEGIN_MESSAGE_MAP(CMyShapedFormView, CFormView) with BEGIN_MESSAGE_MAP(CMyShapedFormView, CHMXShapedFormView)
  • In OnInitialUpdate: add GetParentFrame()->RecalcLayout(); & ResizeParentToFit(FALSE);

Special Thanks to:

  • Davide Calabro' and his CButtonST
  • Norm Almond and his CLabel
  • David Gallardo Llopis and his AnyForm project
  • Jörg König and his CDIBitmap & CBmpPalette
  • Donatella, my wife, for her huge patience :)

Disclaimer

THE SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO RESPONSIBILITIES FOR POSSIBLE DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE RISK OF USING THIS SOFTWARE.

Terms of Use

THIS SOFTWARE IS FREE FOR PERSONAL USE, FREEWARE OR COMMERCIAL APPLICATIONS.

Last and Least

Few minutes to waste? Visit my home page and sing my guestbook.

License

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


Written By
Software Developer (Senior) SOFTHOR
Italy Italy
Too lazy to write something about me...

Comments and Discussions

 
BugThe Tooltip of CHMXStatic does not work. Pin
ymh123200130-Dec-13 16:35
ymh123200130-Dec-13 16:35 
GeneralchmxListCtrl Pin
kip_chuko20-Sep-10 21:06
kip_chuko20-Sep-10 21:06 
GeneralGreat !! Pin
futurejo2-Apr-10 22:13
futurejo2-Apr-10 22:13 
GeneralМнение Pin
drweb8622-Sep-09 4:00
drweb8622-Sep-09 4:00 
QuestionHow do you test for focus of a CEdit? Pin
greateet12-Feb-09 2:01
greateet12-Feb-09 2:01 
AnswerRe: How do you test for focus of a CEdit? Pin
Michael Pauli12-Feb-09 2:31
Michael Pauli12-Feb-09 2:31 
GeneralRe: How do you test for focus of a CEdit? Pin
greateet13-Feb-09 12:28
greateet13-Feb-09 12:28 
GeneralCheckboxes Pin
kiranin2-Feb-09 19:30
kiranin2-Feb-09 19:30 
GeneralRe: Checkboxes Pin
Massimo Colurcio3-Feb-09 3:41
professionalMassimo Colurcio3-Feb-09 3:41 
GeneralRe: Checkboxes Pin
kiranin3-Feb-09 17:55
kiranin3-Feb-09 17:55 
GeneralRe: Checkboxes Pin
Ahmed Alaa9-Mar-09 22:06
Ahmed Alaa9-Mar-09 22:06 
GeneralRe: Checkboxes Pin
rbrunton5-May-20 8:17
rbrunton5-May-20 8:17 
QuestionJPEG s? Pin
kiranin14-Dec-06 19:06
kiranin14-Dec-06 19:06 
AnswerRe: JPEG s? Pin
Massimo Colurcio3-Feb-09 3:39
professionalMassimo Colurcio3-Feb-09 3:39 
GeneralRe: JPEG s? Pin
kiranin3-Feb-09 18:10
kiranin3-Feb-09 18:10 
GeneralCDateTimeCtrl color Pin
G.A.9-Dec-04 21:05
G.A.9-Dec-04 21:05 
GeneralRe: CDateTimeCtrl color Pin
Anonymous27-Jan-05 11:32
Anonymous27-Jan-05 11:32 
GeneralGreat and useful article!!! Pin
G.A.3-Dec-04 3:15
G.A.3-Dec-04 3:15 
Great and useful article!!!
Thanks to Massimo.

GeneralProblemi con VC++ .NET Pin
CelticEye13-Dec-03 9:14
CelticEye13-Dec-03 9:14 
GeneralRe: Problemi con VC++ .NET Pin
Massimo Colurcio23-Feb-04 0:04
professionalMassimo Colurcio23-Feb-04 0:04 
GeneralKillfocus Pin
mrodriguez7-Oct-03 16:31
mrodriguez7-Oct-03 16:31 
GeneralKillfocus & Setfocus - Fixing the problem Pin
Axcel23-Oct-03 21:13
Axcel23-Oct-03 21:13 
GeneralRe: Killfocus & Setfocus - Fixing the problem Pin
Massimo Colurcio25-Oct-03 2:53
professionalMassimo Colurcio25-Oct-03 2:53 
Generaluse CLabel instead of CHMXStatic Pin
joeriw13-Feb-03 2:18
joeriw13-Feb-03 2:18 
QuestionWhere's that update? Pin
joeriw13-Feb-03 0:53
joeriw13-Feb-03 0:53 

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.