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

Extended Use of CStatic Class - CLabel 1.6

By , 2 Aug 2002
 

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

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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy only problem with this class is...memberRavi Bhavnani28-Mar-04 8:44 
GeneralProblems Setting Window Statememberyofnik8-Mar-04 10:10 
GeneralUNICODEmemberExtraLean20-Feb-04 9:21 
GeneralTransparency bugmemberEPulse15-Nov-03 19:22 
GeneralRe: Transparency bugmemberalexuh21-Feb-08 6:14 
GeneralError loading IDC_HAND cursormemberMarcus Carey24-Jul-03 19:46 
Generaladd #define IDC_HAND MAKEINTRESOURCE(32649)memberuranium991-Aug-03 2:43 
Generalfont size isn't changingmemberconnorwr29-May-03 18:02 
GeneralRe: font size isn't changingmemberconnorwr29-May-03 18:33 
GeneralMemory LeakmemberjimNLX28-Apr-03 7:31 
GeneralRe: Memory LeakmemberSledgeHammer28-Apr-03 8:53 
GeneralRe: Memory LeakmemberjimNLX28-Apr-03 9:46 
GeneralText Wrappingmemberzipo1316-Feb-03 6:14 
GeneralRe: Text WrappingmemberChen-Cha Hsu30-Sep-03 15:39 
GeneralMemory LeaksussAnonymous4-Feb-03 9:47 
GeneralRe: Memory LeaksussAnonymous4-Feb-03 10:14 
GeneralRe: Memory LeakmemberNorm Almond5-Feb-03 6:19 
GeneralRe: Memory Leakmemberlily0lin19-Dec-03 16:03 
GeneralRe: Memory Leakmember_corey_17-Nov-03 21:16 
GeneralRe: Memory LeakmemberNorm Almond3-Feb-04 0:30 
GeneralRe: Memory LeakmemberNorm Almond3-Feb-04 1:59 
GeneralThe underst line at the gradient fill locks badmemberNitromouse18-Dec-02 5:59 
GeneralRe: The underst line at the gradient fill locks badmemberNitromouse18-Dec-02 6:02 
GeneralPlease insert a tooltip functionmemberNitromouse18-Dec-02 5:33 
GeneralRe: Please insert a tooltip functionmemberNorm Almond18-Dec-02 6:12 
GeneralRe: Please insert a tooltip functionmemberNorm Almond3-Feb-04 2:01 
QuestionHow to change the Bockground color of SDI form?memberExceter3-Dec-02 22:46 
AnswerRe: How to change the Bockground color of SDI form?memberNorberto Cerezal19-Feb-03 23:35 
QuestionXP visual theme ?membersaruman24-Oct-02 9:46 
AnswerRe: XP visual theme ?membersaruman1-Nov-02 8:19 
GeneralRedundant line of code.memberWREY27-Sep-02 13:08 
GeneralThanks! you make my job easier!memberJohn Wong14-Sep-02 7:07 
GeneralRe: Thanks! you make my job easier!memberNorm Almond14-Sep-02 10:08 
QuestionHow to do use this in a view?memberpankkk1-Sep-02 23:59 
AnswerRe: How to do use this in a view?memberNorm Almond14-Sep-02 10:07 
GeneralTooltipsmembergjr22-Aug-02 14:12 
GeneralFlick free (minimal fixed)memberCloudway23-Apr-02 16:57 
GeneralRe: Flick free (minimal fixed)memberWREY27-Sep-02 12:42 
GeneralRe: Flick free (minimal fixed)membersoultrap10-Jan-03 6:43 
GeneralRe: Flick free (minimal fixed)memberPhil C15-Jan-06 12:54 
GeneralCenter AlignmentmemberPaulJ9-Apr-02 9:51 
GeneralGreat!memberJ. Sze6-Mar-02 22:53 
GeneralVery Good Job !memberFred D.10-Jan-02 3:18 
GeneralCan't get dimmed state from OnInitDialog()memberalexkzk27-Dec-01 22:28 
GeneralSetText function and crashingmemberJim Farmelant28-Nov-01 2:52 
QuestionMay I set icon with text?memberEugene Pustovoyt25-Nov-01 19:50 
General'\t' in text doesn't appear..memberJignesh I. Patel16-Oct-01 4:30 
GeneralFix...memberJignesh I. Patel16-Oct-01 4:43 
GeneralPreSubclassWindow CrashmemberBernie6-Aug-01 0:16 
GeneralBackground flashing code gone in v1.5memberColin Urquhart31-Jul-01 18:17 

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130619.1 | Last Updated 3 Aug 2002
Article Copyright 2000 by NormDroid
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid