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

CFontStatic for PocketPC

, 28 Oct 2004
Rate this:
Please Sign up or sign in to vote.
A class for setting various attributes of static text such as font, color, or alignment.

Sample Image - CFontStatic.gif

Introduction

This is a port of Patrik Svensson's CFontStatic class to PocketPC with a few modifications. The class allows to easily set various attributes of static text such as color, font or alignment.

Using the code

The CFontStatic class contains the following methods:

// set background color
void SetBackground(DWORD dwBgColor);
void SetBackground(int red, int green, int blue);

// set text color
void SetForeground(DWORD dwForeColor);
void SetForeground(int red, int green, int blue);

// set font attributes
void SetFontStatic(CString szFont, int nSize, 
                   DWORD dwColor, FontStyle dwStyle);
void SetFontStatic(CString szFont, int nSize);
void SetFontStatic(CString szFont);
void SetFontSize(int nSize);
void SetFontStyle(FontStyle dwStyle);

// set text alignment
void SetAlignment(AlignStyle style);

In order to use the class, you need to either declare an instance of the class in your code:

CFontStatic myLabel;

or associate a CFontStatic member of the dialog/view class with a resource in DoDataExchange():

DDX_Control(pDX, IDC_LBL_TOP, m_myLabel);

Here is an example of setting various attributes. You can either set them all in one hit, or only set the ones you need:

// set all attributes in one hit
m_lblTop.SetFontStatic(_T("Courier New"), 
         16, RGB(255, 255, 255), CFontStatic::FS_BOLD);

// alignment is set separately
m_lblMid.SetAlignment(CFontStatic::FS_CENTER);
m_lblMid.SetFontStatic(_T("Tahoma"), 18, GetSysColor(COLOR_STATICTEXT), 
                                         CFontStatic::FS_UNDERLINED);

// set attributes one by one
m_lblBot.SetBackground(255, 255, 255);
m_lblBot.SetForeground(0, 0, 128);
m_lblBot.SetFontSize(20);
m_lblBot.SetFontStatic(_T("Frutiger Linotype"));
m_lblBot.SetFontStyle(CFontStatic::FS_ITALIC);
// note that multiple calls of SetFontStyle()
// are needed to set more than one attribute
m_lblBot.SetFontStyle(CFontStatic::FS_UNDERLINED); 
m_lblBot.SetAlignment(CFontStatic::FS_RIGHT);

History

  • 29/10/2004 - Initial submission.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

110_110_110
Web Developer
New Zealand New Zealand
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 29 Oct 2004
Article Copyright 2004 by 110_110_110
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid