Click here to Skip to main content
Click here to Skip to main content

Fancy controls

, 23 Nov 2001
Rate this:
Please Sign up or sign in to vote.
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 quickly solution for a fancy look for all new programs. Of course these aren't classes which you cannot live without. But, I'm sure, sometime 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 Smile | :) ) ]".

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

#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 represent a LOGFONT structure
Get text font GetTextFont(lpLogFont) lpLogFont represent 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

#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 represent a LOGFONT structure
Get text font GetTextFont(lpLogFont) lpLogFont represent 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

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,

#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

#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 represent a LOGFONT structure
Get text font GetTextFont(lpLogFont) lpLogFont represent 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

#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 represent a LOGFONT structure
Get text font GetTextFont(lpLogFont) lpLogFont represent 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 e background colors you have to use the CHMXListBox class.

Don't forget to

#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 represent a LOGFONT structure
Get text font GetTextFont(lpLogFont) lpLogFont represent 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 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 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 by 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 works correctly make following changes:

  • open MyDialog.h,
  • type
    #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 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:

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 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

Using Visual Studio Resource Editor, design your own form and, via Class wizard, create your CMyFormView.
In order to let CHMXFormView derived class works correctly make following changes:
  • open MyFormView.h,
  • type
    #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 & controls make-up,
  • open MyFormView.cpp,
  • make 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:

	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 this instructions you can get the right results. Desing 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 Smile | :)

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)

About the Author

Massimo Colurcio
Software Developer (Senior)
Italy Italy
Too lazy to write something about me...

Comments and Discussions

 
BugThe Tooltip of CHMXStatic does not work. Pinmemberymh123200130-Dec-13 16:35 
GeneralchmxListCtrl Pinmemberkip_chuko20-Sep-10 21:06 
GeneralGreat !! Pinmemberfuturejo2-Apr-10 22:13 
GeneralМнение PinmemberCuchuk Sergey22-Sep-09 4:00 
QuestionHow do you test for focus of a CEdit? Pinmembergreateet12-Feb-09 2:01 
AnswerRe: How do you test for focus of a CEdit? PinmemberMichael Mogensen12-Feb-09 2:31 
GeneralRe: How do you test for focus of a CEdit? Pinmembergreateet13-Feb-09 12:28 
GeneralCheckboxes Pinmemberkiranin2-Feb-09 19:30 
GeneralRe: Checkboxes PinmemberMassimo Colurcio3-Feb-09 3:41 
GeneralRe: Checkboxes Pinmemberkiranin3-Feb-09 17:55 
GeneralRe: Checkboxes PinmemberAhmed Alaa9-Mar-09 22:06 
QuestionJPEG s? Pinmemberkiranin14-Dec-06 19:06 
AnswerRe: JPEG s? PinmemberMassimo Colurcio3-Feb-09 3:39 
GeneralRe: JPEG s? Pinmemberkiranin3-Feb-09 18:10 
GeneralCDateTimeCtrl color PinmemberG.A.9-Dec-04 21:05 
GeneralRe: CDateTimeCtrl color PinsussAnonymous27-Jan-05 11:32 
GeneralGreat and useful article!!! PinmemberG.A.3-Dec-04 3:15 
GeneralProblemi con VC++ .NET PinmemberCelticEye13-Dec-03 9:14 
GeneralRe: Problemi con VC++ .NET PinmemberMassimo Colurcio23-Feb-04 0:04 
GeneralKillfocus Pinmembermrodriguez7-Oct-03 16:31 
GeneralKillfocus & Setfocus - Fixing the problem PinmemberAxcel23-Oct-03 21:13 
GeneralRe: Killfocus & Setfocus - Fixing the problem PinmemberMassimo Colurcio25-Oct-03 2:53 
Generaluse CLabel instead of CHMXStatic Pinmemberjoeriw13-Feb-03 2:18 
QuestionWhere's that update? Pinmemberjoeriw13-Feb-03 0:53 
AnswerRe: Where's that update? Pinmemberbrian scott18-Nov-03 8:40 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 24 Nov 2001
Article Copyright 2001 by Massimo Colurcio
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid