Click here to Skip to main content
11,494,407 members (71,158 online)
Click here to Skip to main content

Extended Use of CStatic Class - CLabel 1.6

, 2 Aug 2002 335.4K 8.9K 160
Rate this:
Please Sign up or sign in to vote.
A fully stocked owner drawn CStatic class

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, 

                            
          COLORREF crBkgndHigh = 0, 

                            
          BackFillMode mode = Normal);

          
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

Share

About the Author

NormDroid
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
Follow on   Twitter

Comments and Discussions

 
GeneralWhite flash with transperent label Pin
lily0lin4-May-04 9:00
memberlily0lin4-May-04 9:00 
GeneralMy only problem with this class is... Pin
Ravi Bhavnani28-Mar-04 9:44
memberRavi Bhavnani28-Mar-04 9:44 
GeneralProblems Setting Window State Pin
yofnik8-Mar-04 11:10
memberyofnik8-Mar-04 11:10 
GeneralUNICODE Pin
ExtraLean20-Feb-04 10:21
memberExtraLean20-Feb-04 10:21 
GeneralTransparency bug Pin
EPulse15-Nov-03 20:22
memberEPulse15-Nov-03 20:22 
GeneralRe: Transparency bug Pin
alexuh21-Feb-08 7:14
memberalexuh21-Feb-08 7:14 
GeneralError loading IDC_HAND cursor Pin
Marcus Carey24-Jul-03 20:46
memberMarcus Carey24-Jul-03 20:46 
Generaladd #define IDC_HAND MAKEINTRESOURCE(32649) Pin
uranium991-Aug-03 3:43
memberuranium991-Aug-03 3:43 
Generalfont size isn't changing Pin
connorwr29-May-03 19:02
memberconnorwr29-May-03 19:02 
GeneralRe: font size isn't changing Pin
connorwr29-May-03 19:33
memberconnorwr29-May-03 19:33 
GeneralMemory Leak Pin
jimNLX28-Apr-03 8:31
memberjimNLX28-Apr-03 8:31 
GeneralRe: Memory Leak Pin
SledgeHammer28-Apr-03 9:53
memberSledgeHammer28-Apr-03 9:53 
GeneralRe: Memory Leak Pin
jimNLX28-Apr-03 10:46
memberjimNLX28-Apr-03 10:46 
GeneralText Wrapping Pin
zipo1316-Feb-03 7:14
memberzipo1316-Feb-03 7:14 
GeneralRe: Text Wrapping Pin
Chen-Cha Hsu30-Sep-03 16:39
memberChen-Cha Hsu30-Sep-03 16:39 
GeneralMemory Leak Pin
Anonymous4-Feb-03 10:47
sussAnonymous4-Feb-03 10:47 
GeneralRe: Memory Leak Pin
Anonymous4-Feb-03 11:14
sussAnonymous4-Feb-03 11:14 
GeneralRe: Memory Leak Pin
Norm Almond5-Feb-03 7:19
memberNorm Almond5-Feb-03 7:19 
GeneralRe: Memory Leak Pin
lily0lin19-Dec-03 17:03
memberlily0lin19-Dec-03 17:03 
GeneralRe: Memory Leak Pin
_corey_17-Nov-03 22:16
member_corey_17-Nov-03 22:16 
GeneralRe: Memory Leak Pin
Norm Almond3-Feb-04 1:30
memberNorm Almond3-Feb-04 1:30 
GeneralRe: Memory Leak Pin
Norm Almond3-Feb-04 2:59
memberNorm Almond3-Feb-04 2:59 
GeneralThe underst line at the gradient fill locks bad Pin
Nitromouse18-Dec-02 6:59
memberNitromouse18-Dec-02 6:59 
GeneralRe: The underst line at the gradient fill locks bad Pin
Nitromouse18-Dec-02 7:02
memberNitromouse18-Dec-02 7:02 
GeneralPlease insert a tooltip function Pin
Nitromouse18-Dec-02 6:33
memberNitromouse18-Dec-02 6:33 
GeneralRe: Please insert a tooltip function Pin
Norm Almond18-Dec-02 7:12
memberNorm Almond18-Dec-02 7:12 
GeneralRe: Please insert a tooltip function Pin
Norm Almond3-Feb-04 3:01
memberNorm Almond3-Feb-04 3:01 
QuestionHow to change the Bockground color of SDI form? Pin
Exceter3-Dec-02 23:46
memberExceter3-Dec-02 23:46 
AnswerRe: How to change the Bockground color of SDI form? Pin
Norberto Cerezal20-Feb-03 0:35
memberNorberto Cerezal20-Feb-03 0:35 
QuestionXP visual theme ? Pin
saruman24-Oct-02 10:46
membersaruman24-Oct-02 10:46 
AnswerRe: XP visual theme ? Pin
saruman1-Nov-02 9:19
membersaruman1-Nov-02 9:19 
GeneralRedundant line of code. Pin
WREY27-Sep-02 14:08
memberWREY27-Sep-02 14:08 
GeneralThanks! you make my job easier! Pin
John Wong14-Sep-02 8:07
memberJohn Wong14-Sep-02 8:07 
GeneralRe: Thanks! you make my job easier! Pin
Norm Almond14-Sep-02 11:08
memberNorm Almond14-Sep-02 11:08 
QuestionHow to do use this in a view? Pin
pankkk2-Sep-02 0:59
memberpankkk2-Sep-02 0:59 
AnswerRe: How to do use this in a view? Pin
Norm Almond14-Sep-02 11:07
memberNorm Almond14-Sep-02 11:07 
GeneralTooltips Pin
gjr22-Aug-02 15:12
membergjr22-Aug-02 15:12 
GeneralFlick free (minimal fixed) Pin
Cloudway23-Apr-02 17:57
memberCloudway23-Apr-02 17:57 
GeneralRe: Flick free (minimal fixed) Pin
WREY27-Sep-02 13:42
memberWREY27-Sep-02 13:42 
GeneralRe: Flick free (minimal fixed) Pin
soultrap10-Jan-03 7:43
membersoultrap10-Jan-03 7:43 
GeneralRe: Flick free (minimal fixed) Pin
Phil C15-Jan-06 13:54
memberPhil C15-Jan-06 13:54 
GeneralCenter Alignment Pin
PaulJ9-Apr-02 10:51
memberPaulJ9-Apr-02 10:51 
GeneralGreat! Pin
J. Sze6-Mar-02 23:53
memberJ. Sze6-Mar-02 23:53 
GeneralVery Good Job ! Pin
Fred D.10-Jan-02 4:18
memberFred D.10-Jan-02 4:18 
GeneralCan't get dimmed state from OnInitDialog() Pin
alexkzk27-Dec-01 23:28
memberalexkzk27-Dec-01 23:28 
GeneralSetText function and crashing Pin
Jim Farmelant28-Nov-01 3:52
memberJim Farmelant28-Nov-01 3:52 
QuestionMay I set icon with text? Pin
Eugene Pustovoyt25-Nov-01 20:50
memberEugene Pustovoyt25-Nov-01 20:50 
General'\t' in text doesn't appear.. Pin
Jignesh I. Patel16-Oct-01 5:30
memberJignesh I. Patel16-Oct-01 5:30 
GeneralFix... Pin
Jignesh I. Patel16-Oct-01 5:43
memberJignesh I. Patel16-Oct-01 5:43 
GeneralPreSubclassWindow Crash Pin
Bernie6-Aug-01 1:16
memberBernie6-Aug-01 1:16 

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 | Terms of Use | Mobile
Web02 | 2.8.150520.1 | Last Updated 3 Aug 2002
Article Copyright 2000 by NormDroid
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid