Enumerating and Adding Fonts in Windows CE

A newsgroup post today reminded me of a simple app I wrote a few years back that enumerates all Fonts on a CE device, then searches a specific location (an inserted storage card in this case), adds any fonts found, then re-enumerates all the existing fonts.


Here’s the code, in its entirety:


#include <windows.h>

#define FONT_PATH    (_T(“\Storage Card”))

void FindFonts(TCHAR *location, TCHAR *type);
int CALLBACK EnumFontFamProc(ENUMLOGFONT *lpelf, TEXTMETRIC *lpntm,
                             int FontType, LPARAM lParam);

int WINAPI WinMain(
HINSTANCE hInst,
HINSTANCE hInstPrev,
LPTSTR lpszCmdLine,
int nCmdShow)
{
    HDC    pDC = GetDC(NULL);
    //
    // Enumerate all the fonts
    //
    RETAILMSG(TRUE, (_T(“rn——————————rn”)));
    RETAILMSG(TRUE, (_T(“Available Fonts on this devicern——————————rn”)));
    EnumFontFamilies(pDC, NULL, (FONTENUMPROC)EnumFontFamProc, NULL);
    RETAILMSG(TRUE, (_T(“——————————rnn”)));

    RETAILMSG(TRUE, (_T(“Looking for fonts on Storage Card…rn”)));


    // TrueType file (.ttf)
    FindFonts(FONT_PATH, _T(“TTF”));
    // TrueType resource file (.fot)
    FindFonts(FONT_PATH, _T(“FOT”));
    // TrueType collection file (.ttc)
    FindFonts(FONT_PATH, _T(“TTC”));
    // raw bitmap font file (.fnt)
    FindFonts(FONT_PATH, _T(“FNT”));
    // raster resource file (.fon)
    FindFonts(FONT_PATH, _T(“FON”));


    RETAILMSG(TRUE, (_T(“rn——————————rn”)));
    RETAILMSG(TRUE, (_T(“Available Fonts on this devicern——————————rn”)));
    EnumFontFamilies(pDC, NULL, (FONTENUMPROC)EnumFontFamProc, NULL);
    RETAILMSG(TRUE, (_T(“——————————rnn”)));

    ReleaseDC(NULL, pDC);

    return 0;
}

void FindFonts(TCHAR *location, TCHAR *type)
{
    TCHAR fontpath[MAX_PATH];
    TCHAR findpath[MAX_PATH];

    WIN32_FIND_DATA fd;

    _stprintf(findpath, _T(“%s\*.%s”), location, type);

    HANDLE hFind = FindFirstFile(findpath, &fd);
    
    if(hFind != INVALID_HANDLE_VALUE)
    {
        RETAILMSG(TRUE, (_T(” found %srn”), fd.cFileName));
        _stprintf(fontpath, _T(“\Storage Card\%s”), fd.cFileName);

        AddFontResource(fontpath);

        while(FindNextFile(hFind, &fd))
        {
            RETAILMSG(TRUE, (_T(” found %srn”), fd.cFileName));
            _stprintf(fontpath, _T(“\Storage Card\%s”), fd.cFileName);
            AddFontResource(fontpath);
        }
    }
    FindClose(hFind);
}

int CALLBACK EnumFontFamProc(ENUMLOGFONT *lpelf, TEXTMETRIC *lpntm,
                             int FontType, LPARAM lParam)
{
    RETAILMSG(TRUE, (_T(“t%srn”), lpelf->elfFullName));

    return 1;
}

2 thoughts on “Enumerating and Adding Fonts in Windows CE”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s