CNewLabel : Advanced CStatic-Derived Class
Posted
by Mike Marquet
on February 16th, 2001
This class (CNewLabel) is derived from CStatic and performs a lot of things that the CStatic class can not do:
- Text colour
- Background colour
- Text background colour
- Fonts
- Multi line support with text justification
- Link text (with or without cursor)
- Text highlighting when mouse moves over static control
- Centred background image (stretched or not with or without text)
- Text rotation (00 - 900 - 1800 - 2700) (separated CTextRotator class)
- Bevel lines support
- Text flashing
- Background flashing
- Control tool tips (separated CControlToolTip class)
CNewLabel API
// Colour functions //Set the background colour of the control. CNewLabel& SetBkColor(COLORREF clr) //Set the text colour of the control. CNewLabel& SetTextColor(COLORREF clr) //Set the background colour of the text background. CNewLabel& SetTextBackColor(COLORREF clr) //Set the highlighting colour. CNewLabel& SetHighLightColor(COLORREF clr) //Set the control to use the default background //colour (COLOR_3DFACE). CNewLabel& SetDefaultBkColor() //Set the control to use the default text //colour (COLOR_WINDOWTEXT). CNewLabel& SetDefaultTextColor() //Set the control to use the default text //background colour (COLOR_3DFACE). CNewLabel& SetDefaultTextBackColor() //Font functions //Toggles the state of the bold attribute of the text in //the control. CNewLabel& SetFontBold(BOOL bSet) //Toggles the state of the italic font attribute of //the control. CNewLabel& SetFontItalic(BOOL bSet) //Toggles the state of the underline font attribute of //the control. CNewLabel& SetFontUnderline(BOOL bSet) //Sets the fonts face name. CNewLabel& SetFontName(LPCTSTR lpszFaceName) //Sets the fonts size in points. CNewLabel& SetFontSize(int iSize) // Other functions //Toggles the state of the background flashing attribute. CNewLabel& FlashBackground(BOOL bActivate, UINT uiTime) //Toggles the state of the text flashing attribute. CNewLabel& FlashText(BOOL bActivate, UINT uiTime) //Set the text justification (see under for defines). CNewLabel& SetAlignment(UINT uiAlign) //Set the text rotation angle (0, 90 , 180 or 270). CNewLabel& SetAngle(UINT uiAngle) //Set (or remove) the background image. CNewLabel& SetBackImage(UINT nID) //Toggles the state of the borders attribute. CNewLabel& SetBorder(BOOL bSet) //Set the control cursor. CNewLabel& SetCursor(HCURSOR hCursor) //Set the control cursor. CNewLabel& SetCursor(UINT uiCursorID) //Toggles the state of the disabled attribute. CNewLabel& SetDisabled(BOOL bSet) //Toggles the state of the link attribute. CNewLabel& SetLink(BOOL bSet) //Sets the cursor for the link. CNewLabel& SetLinkCursor(HCURSOR hCursor) //Sets the cursor for the link. CNewLabel& SetLinkCursor(UINT uiCursorID) //Toggles the state of the lower case attribute. CNewLabel& SetLowerCase(BOOL bSet) //Set the text of the control. CNewLabel& SetText(LPCTSTR lpszText) //Set the tool tip position //(0 = Over, 1 = Under, 2 = Above). CNewLabel& SetToolTipPosition(int iPos) //Set the tool tip text. CNewLabel& SetToolTipText(LPCTSTR lpszText) //Toggles the state of the sunken attribue of //the control. CNewLabel& SetSunken(BOOL bSet) //Toggles the state of the upper case attribute. CNewLabel& SetUpperCase(BOOL bSet) //Toggles the state of the vertical text attribute. CNewLabel& SetVerticalText(BOOL bSet) //Toggles the state how the tool tip must appear. CNewLabel& ShowToolTipOnlyOnMouseClick(BOOL b) //Stretch or not the centred bitmap. CNewLabel& StretchBitmap(BOOL bStrecth) //Display or not the bevel line. CNewLabel& UseBevelLine(BOOL bUse) //Toggles the state of the highlighting mode. CNewLabel& UseHighLighting(BOOL bUse) //Use tool tip or not. CNewLabel& UseToolTip(BOOL bUse) //Use highlighting only with a filled tool tip. CNewLabel& UseHighLightingOnlyWithMouseToolTip(BOOL b) //Use left mouse button for tool tip. CNewLabel& UseLeftMouseButtonForToolTip(BOOL bUse)For GET functions, see source code!
Text justification defines:
- HORZ_LEFT - For left justification
- HORZ_CENTER - For horizontal center
- HORZ_RIGHT - For right justification
- VERT_TOP - For top justification
- VERT_CENTER - For vertical center
- VERT_BOTTOM - For bottom justification
Example of CNewLabel
m_NL_TextColor.SetTextColor(RGB(255,0,0));
m_NL_BackgndColor.SetBkColor(RGB(255,255,0));
m_NL_BackTextColor.SetTextBackColor(RGB(0,255,0));
m_NL_BackTextColor.SetBkColor(RGB(255,255,0));
m_NL_Angle0.SetAngle(0);
m_NL_Angle90.SetAngle(90);
m_NL_Angle180.SetAngle(180);
m_NL_Angle270.SetAngle(270);
m_NL_FontText.SetText("Font Text\n+Border");
m_NL_FontText.SetFontBold(TRUE);
m_NL_FontText.SetFontName("Times New Roman");
m_NL_FontText.SetFontSize(20);
m_NL_FontText.SetBorder(TRUE);
m_NL_MultiLineText.SetText("Multi Line Text\n"
"Right Aligned\nBottom "
"Aligned\nSunken effect");
m_NL_MultiLineText.SetAlignment(CNewLabel::HORZ_RIGHT
| CNewLabel::VERT_BOTTOM);
m_NL_MultiLineText.SetSunken(TRUE);
m_NL_FlashingText.FlashText(TRUE);
m_NL_FlashBack.FlashBackground(TRUE, 600);
m_NL_DisabledText.SetDisabled(TRUE);
m_NL_LinkText.SetLink(TRUE);
m_NL_LinkText.SetLinkCursor(IDC_HAND);
m_NL_LinkText.SetTextColor(RGB(0,0,255));
m_NL_HighLightingText.UseHighLighting(TRUE);
m_NL_HighLightingText.SetHighLightColor(RGB(255,0,255));
m_NL_TextWithToolTip1.UseToolTip(TRUE);
m_NL_TextWithToolTip1.SetToolTipText("Tooltip text "
"over control");
m_NL_TextWithToolTip1.ShowToolTipOnlyOnMouseClick(FALSE);
m_NL_TextWithToolTip2.UseToolTip(TRUE);
m_NL_TextWithToolTip2.SetToolTipText("Tooltip text under control "
"+ highlighting");
m_NL_TextWithToolTip2.SetToolTipPosition(1);
m_NL_TextWithToolTip2.UseHighLighting(TRUE);
m_NL_TextWithToolTip2.SetHighLightColor(RGB(255,0,255));
m_NL_TextWithToolTip3.UseToolTip(TRUE);
m_NL_TextWithToolTip3.SetToolTipText("Tooltip text above"
" control + highlighting");
m_NL_TextWithToolTip3.SetToolTipPosition(2);
m_NL_TextWithToolTip3.UseLeftMouseButtonForToolTip(FALSE);
m_NL_TextWithToolTip3.UseHighLighting(TRUE);
m_NL_TextWithToolTip3.SetHighLightColor(RGB(255,0,255));
m_NL_bevelTextRight.UseBevelLine(TRUE);
m_NL_bevelTextCenter.UseBevelLine(TRUE);
m_NL_bevelTextLeft.UseBevelLine(TRUE);
m_NL_BevelTextTop.UseBevelLine(TRUE);
m_NL_BevelTextTop.SetAngle(90);
m_NL_BevelTextVCenter.UseBevelLine(TRUE);
m_NL_BevelTextVCenter.SetAngle(90);
m_NL_BevelTextBottom.UseBevelLine(TRUE);
m_NL_BevelTextBottom.SetAngle(90);
m_NL_BevelTextBottom.SetAlignment(CNewLabel::HORZ_LEFT
| CNewLabel::VERT_BOTTOM);
m_NL_VerticalText.SetVerticalText(TRUE);
m_NL_VerticalText.SetUpperCase(TRUE);
m_NL_BitmapWithoutText.SetBackImage(IDB_MIKE);
m_NL_BitmapWithoutText.StretchBitmap(TRUE);
m_NL_BitmapWithText.SetBackImage(IDB_MIKE);
m_NL_BitmapWithText.SetTextColor(RGB(255,255,0));
m_NL_BitmapWithText.SetAlignment(CNewLabel::HORZ_CENTER
| CNewLabel::VERT_BOTTOM);
m_NL_BitmapWithText.StretchBitmap(TRUE);
Downloads
Download demo project - 74 KbDownload demo application (debug build) - 50 Kb

Comments
There are no comments yet. Be the first to comment!