Click here to Skip to main content
15,867,488 members
Articles / Desktop Programming / MFC
Article

Extended Use of CStatic Class - CLabel 1.6

Rate me:
Please Sign up or sign in to vote.
4.90/5 (59 votes)
2 Aug 2002 431.1K   11.8K   170   113
A fully stocked owner drawn CStatic class

Image 1

Introduction

Ever wanted a static control that behaved like a Visual Basic label control? Well this could be just the thing you might be looking for. This version adds all the functionality of the label control, plus many other features. The control uses double buffering which gives fast painting. The real work in done in the OnPaint function.

I've called the class CLabel and its simple to use in dialog boxes, just follow this simple instructions.

  1. Design the dialog box in the normal way.
  2. Create an OnInitDialog function using the class wizard.
  3. Add Label.cpp and Label.h to your project.
  4. #Include <label.cpp> in your dialog .cpp file.
  5. Delete the project '.clw' file and regenerate by opening the project and pressing Ctrl+W
  6. Any static controls that need enhancing, give each control a unique ID within the dialog editor.
  7. Assign each member controls (CLabel) to each ID using the class wizard.
  8. In OnInitDialog uses the CLabelAPI to change the appearance of the control.

API of CLabel

CLabel& SetBkColor(COLORREF crBkgnd, <br>
                           
         COLORREF crBkgndHigh = 0, <br>
                           
         BackFillMode mode = Normal);<br>
Set the background colour of the control and allows an optional gradient fill.
CLabel& SetText(const CString&
          strText)
Sets the text of the controls
CLabel& SetTextColor(COLORREF
          crText)
Sets the text colour of the control
CLabel& SetFontBold(BOOL bBold) Toggles the state of the bold attribute of the text in the control
CLabel& SetFontName(const CString&
          strFont)
The the fonts face name in the control
CLabel& SetFontUnderline(BOOL bSet) Toggles the state of the underline font attribute of the control
CLabel& SetFontItalic(BOOL bSet) Toggles the state of the italic font attribute of the control
CLabel& SetFontSize(int nSize) Sets the fonts size in points.
CLabel& SetSunken(BOOL bSet) Toggles the state of the sunken attribue of the control
CLabel& SetBorder(BOOL bSet) Toggles the state of the borders attribute
CLabel& FlashText(BOOL bSet) Toggles the state of the text flashing attribute
CLabel& FlashBackground(BOOL bSet) Toggles the state of the text flashing attribute
CLabel& SetLink(BOOL bLink) Toggles the state of the link attribute (allows label to become internet link)
CLabel& SetLinkCursor(HCURSOR
          hCursor)
Sets the cursor for the link.
CLabel& SetTransparency(BOOL
          bTransparency)
Sets the transparency for the background.
CLabel& SetFont3D(BOOL bSet,Type3D
          type)
Sets 3D fonts
CLabel& SetRotationAngle(UINT
          nAngle,BOOL bRotation)
Sets rotation angle for font
CLabel&
          SetText3DHiliteColor(COLORREF cr3DHiliteColor)
Sets the hi-light colour for the text
CLabel&
	SetMailLink(BOOL bEnable, BOOL bNotifyParent)
Sets the hi-light colour for the text

Example of use

m_fname.SetFontName("System");
m_fsize.SetFontSize(14);
m_uline.SetFontUnderline(TRUE);
m_tcolor.SetTextColor(RGB(255,0,0));
m_bcolor.SetBkColor(RGB(0,255,255));
m_italics.SetFontItalic(TRUE);
m_bold.SetFontBold(TRUE);
m_border.SetBorder(TRUE);
m_sunken.SetSunken(TRUE);
m_lblGradient.SetBkColor(RGB(255,255,255),RGB(0,0,255), CLabel::Gradient);

m_monty.SetFontName("Arial");
m_monty.SetFontSize(12);
m_monty.SetTextColor(RGB(255,255,0));
m_monty.SetFontUnderline(TRUE);
m_monty.SetBkColor(RGB(0,0,0));
m_monty.SetFontItalic(TRUE);
m_monty.SetFontBold(TRUE);
m_monty.SetBorder(TRUE);
m_monty.SetSunken(TRUE);

History

CLabel Version 1.6

  • Jeroen Roosendaal - SetFont suggestion
  • Laurent - Spotting SelectObject bugs
  • Bernie - Fix PreCreateWindow bug
  • Jignesh I. Patel - Added expanded tabs feature
  • Jim Farmelant - Fix SetText crash

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Software Kinetics
United Kingdom United Kingdom




Software Kinetics
are experts in developing customised and bespoke applications and have expertise in the development of desktop, mobile and internet applications on Windows.


We specialise in:

  • User Interface Design
  • Desktop Development
  • Windows Phone Development
  • Windows Presentation Framework
  • Windows Forms
  • Windows Communication Framework
  • Windows Services
  • Network Applications
  • Database Applications
  • Web Development
  • Web Services
  • Silverlight
  • ASP.net


Visit Software Kinetics

Comments and Discussions

 
GeneralVery Good Job ! Pin
Fred D.10-Jan-02 3:18
Fred D.10-Jan-02 3:18 
GeneralCan't get dimmed state from OnInitDialog() Pin
alexkzk27-Dec-01 22:28
alexkzk27-Dec-01 22:28 
GeneralSetText function and crashing Pin
Jim Farmelant28-Nov-01 2:52
Jim Farmelant28-Nov-01 2:52 
QuestionMay I set icon with text? Pin
Eugene Pustovoyt25-Nov-01 19:50
Eugene Pustovoyt25-Nov-01 19:50 
General'\t' in text doesn't appear.. Pin
J Patel16-Oct-01 4:30
J Patel16-Oct-01 4:30 
GeneralFix... Pin
J Patel16-Oct-01 4:43
J Patel16-Oct-01 4:43 
GeneralPreSubclassWindow Crash Pin
Bernie6-Aug-01 0:16
Bernie6-Aug-01 0:16 
GeneralBackground flashing code gone in v1.5 Pin
Colin Urquhart31-Jul-01 18:17
Colin Urquhart31-Jul-01 18:17 
Hi,

I've been using CLabel v1.4 for some time now (very nice class Cool | :cool: ) and have only recently decided to flash a background.
I noticed that the BG flash code in v1.4 was broken (it used m_hBackBrush to fill in both states of m_bState). Frown | :(
I have only just downloaded v1.5 to see if it had been fixed, and the BG flash code in OnPaint is gone. Confused | :confused:
Do you intend to put it back in future releases or do you consider it a too little used property to worry about ?

Thanks - Col Big Grin | :-D
GeneralConversion to WTL Pin
15-Mar-01 7:01
suss15-Mar-01 7:01 
GeneralOld bitmap not selected back into DC Pin
11-Feb-01 9:33
suss11-Feb-01 9:33 
GeneralRe: Old bitmap not selected back into DC Pin
NormDroid28-Feb-01 8:22
professionalNormDroid28-Feb-01 8:22 
GeneralSetting font properties using LOGFONT Pin
Jeroen Roosendaal5-Jan-01 3:41
Jeroen Roosendaal5-Jan-01 3:41 
GeneralRe: Setting font properties using LOGFONT Pin
NormDroid20-Jan-01 2:02
professionalNormDroid20-Jan-01 2:02 
General### Version 1.5 ### Pin
Norm Almond20-Sep-00 2:56
sussNorm Almond20-Sep-00 2:56 
GeneralRe: ### Version 1.5 ### Pin
Jason Troitsky30-Dec-00 5:56
Jason Troitsky30-Dec-00 5:56 
GeneralRe: ### Version 1.5 ### Pin
NormDroid2-Jan-01 22:00
professionalNormDroid2-Jan-01 22:00 
GeneralRe: ### Version 1.5 ### Pin
4-Jun-01 23:47
suss4-Jun-01 23:47 
GeneralRe: ### Version 1.5 ### Pin
NormDroid14-Dec-02 2:53
professionalNormDroid14-Dec-02 2:53 
GeneralSetFontName() and charset Pin
Alan Chan20-Aug-00 22:17
Alan Chan20-Aug-00 22:17 
GeneralRe: SetFontName() and charset Pin
Norm Almond11-Sep-00 2:39
sussNorm Almond11-Sep-00 2:39 
GeneralFlicker Pin
Colin Urquhart17-Aug-00 20:58
Colin Urquhart17-Aug-00 20:58 
GeneralRe: Flicker Pin
Norm Almond17-Aug-00 22:28
sussNorm Almond17-Aug-00 22:28 
GeneralRe: Flicker Pin
Colin Urquhart11-Sep-00 18:18
Colin Urquhart11-Sep-00 18:18 
GeneralRe: Flicker Pin
Norm Almond14-Sep-00 21:39
sussNorm Almond14-Sep-00 21:39 
GeneralRe: Flicker Pin
Norm Almond15-Sep-00 0:00
sussNorm Almond15-Sep-00 0:00 

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.