In this article I want to introduce two template classes, that can help you in simple dialog development. Very frequently we try to set different color or font to static, editbox or another control in our dialog. To simplify this work I wrote two classes
. These classes have two advantages. First of all, you don’t need to throw out your beloved class. Because these classes are templates – they can be attached to any existing CWnd-based class. Second, there is no painting of any kind in these classes.
CColorCtrl v1.2
Control works in one of two modes:
Simple Colored Mode
Blinking Mode
You can customise:
Text color(s)
Background color(s)
Blinking delay
If your control uses
WM_CTLCOLOR
message for painting (as almost all standard windows controls do), you can use this template. Use it also for whole dialog (see "About" dialog in system menu).
Usage:
Include ColorCtrl.h in your project. Create control with dialog editor. Add member variable for this control with class wizard. Replace
Warning! Don’t use these five classes together with one control.
If your control doesn’t contain font (e.g. you create it in code by call to
Create
function)
CFontCtrl
cannot change font style/height. In this case use one of
SetFont
functions to set font to your control. If you create control on base of one of five derived classes – don’t worry – predefined style/height will be added to selected font.
Common Notes
Any function of any class can be called even before window created.
You can use both classes together for single control:
CFontCtrl<CColorCtrl<CStatic> > m_static;
// or
CColorCtrl<CFontCtrl<CStatic> > m_static;
// or
typedef CFontCtrl<CStatic> CFontStatic;
CColorCtrl<CFontStatic> m_static;
// or even
typedef CFontCtrlEx<CStatic,
FC_FONT_BOLD|FC_FONT_UNDERLINE,
30> CBoldUnderlineStatic;
CColorCtrlEx<CBoldUnderlineStatic,
RGB(255,0,0), RGB(0,255,0)> m_static;