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.
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 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].
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 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 |
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 |
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 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 |
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 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 |
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...
#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 |
Refers to CHMXListBox
.
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:
#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();
|
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.
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:
#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:
GetParentFrame()->RecalcLayout();
ResizeParentToFit(FALSE);
In this way, the form will have the right size.
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.