/*
* FontEnumerator.h
* Copyright (c) 2009 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
// SOL++2000
#pragma once
#include <windows.h>
#include <stdio.h>
namespace SOL {
class FontEnumerator {
private:
int num;
public:
FontEnumerator() {
this->num = 0;
}
public:
//
//
// return Number of enumerated fonts(this->num).
int enumerate(const TCHAR* faceName=_T(""))
{
HDC hDC = GetDC(NULL);
LOGFONT lf = { 0, 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0,
0, _T("") };
strcpy_s(lf.lfFaceName, SizeOf(lf.lfFaceName), faceName);
this-> num=0;
EnumFontFamiliesEx( hDC, &lf, (FONTENUMPROC)EnumFontFamiliesExProc, (LPARAM)this, 0 );
//printf("Num=%d\n", num);
ReleaseDC( NULL, hDC );
return this->num;
}
private:
static int CALLBACK EnumFontFamiliesExProc( ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *lpntme,
int FontType, LPARAM lParam)
{
FontEnumerator* fontEnum = (FontEnumerator*)lParam;
fontEnum->increment();
//Printf( "%s\n", lpelfe->elfFullName );
return 1;
}
public:
void increment() {
num++;
}
public:
int getNumber() {
return num;
}
};
}
/*
int main( int __argc, TCHAR** __argv )
{
const char* faceName = "CI";
FontEnumerator fontEnum;
int n = fontEnum.enumerate(faceName);
printf("Font=%s number =%d\n", faceName, n);
return 0;
}
*/
|