5,286,006 members and growing! (20,427 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » Dialogs and Windows     Intermediate License: The Code Project Open License (CPOL)

A font chooser dialog for the Pocket PC

By Joao Paulo Figueira

Implementing a font chooser dialog with preview and ClearType support.
C++, eVC 3.0, eVC, Windows, WinCE, Visual Studio, MFC, Mobile, WinMobile2002, Dev

Posted: 16 Aug 2003
Updated: 16 Aug 2003
Views: 36,097
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
13 votes for this Article.
Popularity: 4.84 Rating: 4.34 out of 5
1 vote, 7.7%
1
0 votes, 0.0%
2
1 vote, 7.7%
3
3 votes, 23.1%
4
8 votes, 61.5%
5

Sample Image - CeChooseFont.jpg

Introduction

This article describes the implementation of a font chooser dialog for the Pocket PC, with the following features:

  • Font rendering preview
  • ClearType support
  • Property page implementation

The dialog layout was based on Pocket Excel's, and allows you to use the dialog with the SIP up.

Implementation

The dialog was implemented as a property page so you can use it in your own property sheets without change. The demo project uses my own CCePropertySheet class to encapsulate it.

The class uses two public members for interfacing with the user:

  • m_logFont: a LOGFONT variable that receives and returns the font definition. You can use it immediately in CreateFontIndirect.
  • m_strPreview: a CString variable that receives the text you want to render on the preview. By default it is "AaBbCcXxYyZz".

Font enumeration

Font families are enumerated through a call to EnumFontFamilies. This function receives a callback function pointer that will fill up the font combo box. When the dialog is initialized, it tries to match the font specified in m_logFont with the contents of the combo boxes. If it cannot match the font name and size, the dialog will set both name and size in the proper combo boxes. The dialog is not prepared to receive a clean m_logFont, you must fill it in before using the dialog.

ClearType

ClearType support depends on your system supporting it. Please check with your vendor if your device supports ClearType.

Creating a font with the ClearType property is as simple as specifying 5 as the lfQuality member of the LOGFONT structure.

Using the dialog

Using the dialog is very straightforward:

void CChildView::OnChooseFont() 
{
    CCePropertySheet    sheet(_T("Choose Font"));
    CChooseFontPage        page;

    //

    // Create the default font

    //

    page.m_logFont.lfHeight            = -11;
    page.m_logFont.lfWidth            = 0;
    page.m_logFont.lfEscapement        = 0;
    page.m_logFont.lfOrientation    = 0;
    page.m_logFont.lfWeight            = FW_NORMAL;
    page.m_logFont.lfItalic            = FALSE;
    page.m_logFont.lfUnderline        = FALSE;
    page.m_logFont.lfStrikeOut        = 0;
    page.m_logFont.lfCharSet        = ANSI_CHARSET;
    page.m_logFont.lfOutPrecision    = OUT_DEFAULT_PRECIS;
    page.m_logFont.lfClipPrecision    = CLIP_DEFAULT_PRECIS;
    page.m_logFont.lfQuality        = DEFAULT_QUALITY;
    page.m_logFont.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
    _tcscpy(page.m_logFont.lfFaceName, TEXT("Tahoma"));

    sheet.AddPage(&page);

    sheet.DoModal();
}

On exit, the m_logFont variable will have the new font definition, ready to be used.

Adding new fonts

Adding new fonts to your device is simple: just copy the desktop TrueType font files you wish to the device's \Windows\Fonts folder. They will be readily available.

License

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

About the Author

Joao Paulo Figueira


João is a Microsoft Device Application Development MVP and partner at Primeworks, a company that develops remote database access software for Windows Mobile.
Occupation: Software Developer
Company: Primeworks
Location: Antarctica Antarctica

Other popular Mobile Development 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 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralAdding fonts programmatically?memberNimai8:23 4 Mar '05  
GeneralRe: Adding fonts programmatically?memberJoão Paulo Figueira4:46 5 Mar '05  
GeneralRe: Adding fonts programmatically?susssithira21:14 5 Jun '05  
GeneralRe: Adding fonts programmatically?memberJoão Paulo Figueira22:51 5 Jun '05  
GeneralRe: Adding fonts programmatically?susssithira20:30 13 Jun '05  

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

PermaLink | Privacy | Terms of Use
Last Updated: 16 Aug 2003
Editor: Smitha Vijayan
Copyright 2003 by Joao Paulo Figueira
Everything else Copyright © CodeProject, 1999-2008
Web20 | Advertise on the Code Project