5,667,575 members and growing! (16,161 online)
Email Password   helpLost your password?
Desktop Development » Static & Panel Controls » General     Intermediate

Extended Use of CStatic Class - CLabel 1.6

By Norm .net

A fully stocked owner drawn CStatic class
VC6, C++Windows, NT4, MFC, VS6, Visual Studio, Dev

Posted: 11 Jan 2000
Updated: 2 Aug 2002
Views: 206,657
Bookmarked: 95 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
105 votes for this Article.
Popularity: 8.83 Rating: 4.37 out of 5
3 votes, 6.4%
1
0 votes, 0.0%
2
1 vote, 2.1%
3
2 votes, 4.3%
4
41 votes, 87.2%
5

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

About the Author

Norm .net



Occupation: Architect
Company: Software Kinetics
Location: United Kingdom United Kingdom

Other popular Static & Panel Controls articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 100 (Total in Forum: 100) (Refresh)FirstPrevNext
GeneralFlashing problems ( transparent label over bitmap )memberalexuh5:21 13 Aug '08  
GeneralMaybe it's better that set byCharSet=DEFAULT_CHARSET in SetFontName?membersodar18:57 22 May '08  
Generaltext right alignedmemberJ.Charpentier8:05 26 Jun '07  
GeneralRotate Bitmaps?memberfrqftgbdafr11:47 29 May '07  
QuestionHelp on subclassing CLabel for suporting background imagememberovidiu_pos22:03 16 May '07  
QuestionLicense?membertoschlog15:17 16 May '07  
AnswerRe: License?membernorm .net21:57 16 May '07  
GeneralEnable / Disable ?memberChrisRibe7:03 19 Mar '07  
GeneralGot Slow SomewherememberPhil C16:26 27 Dec '05  
GeneralSemi-transparent, colored CLabelmemberDavid Fleming0:10 3 Sep '05  
GeneralSetWindowPosmemberchris.lee@alcormicro.com21:26 29 Mar '05  
GeneralRe: SetWindowPosmemberOsborn6:21 27 Apr '06  
GeneralFlickerring?memberlily0lin10:22 5 May '04  
GeneralRe: Flickerring?memberEastSeaBoy20:49 19 Sep '04  
GeneralRe: Flickerring?memberEvanTao2:47 9 Dec '04  
GeneralRe: Flickerring?memberfeisi17:16 14 Jul '08  
GeneralWhite flash with transperent labelmemberlily0lin9:00 4 May '04  
GeneralMy only problem with this class is...memberRavi Bhavnani9:44 28 Mar '04  
GeneralProblems Setting Window Statememberyofnik11:10 8 Mar '04  
GeneralUNICODEmemberExtraLean10:21 20 Feb '04  
GeneralTransparency bugmemberEPulse20:22 15 Nov '03  
GeneralRe: Transparency bugmemberalexuh7:14 21 Feb '08  
GeneralError loading IDC_HAND cursormemberMarcus Carey20:46 24 Jul '03  
Generaladd #define IDC_HAND MAKEINTRESOURCE(32649)memberuranium993:43 1 Aug '03  
Generalfont size isn't changingmemberconnorwr19:02 29 May '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 2 Aug 2002
Editor: Chris Maunder
Copyright 2000 by Norm .net
Everything else Copyright © CodeProject, 1999-2008
Web13 | Advertise on the Code Project