How to enum installed (ttf) fonts

Posted By: 3dgs_snake

How to enum installed (ttf) fonts - 09/07/10 13:47

Hi,

I just wanted to ask if it is possible to show the font selection dialog - ChooseFont with LOGFONT and CHOOSEFONT structs - (I have tried and failed blush ). I want this because i want to make a graphical font generator to use with the engine. That would also be great if someone can point me to an already made graphical font generator in the format required by 3dgs (no further editing).

this the code :

#include <acknex.h>
#include <windows.h>
#include <default.c>

typedef char TCHAR;
typedef int INT;
typedef char* LPTSTR;
typedef const char* LPCTSTR;

//////////////////////////////
// LOGFONT struct
//////////////////////////////
typedef struct tagLOGFONT {
LONG lfHeight;
LONG lfWidth;
LONG lfEscapement;
LONG lfOrientation;
LONG lfWeight;
BYTE lfItalic;
BYTE lfUnderline;
BYTE lfStrikeOut;
BYTE lfCharSet;
BYTE lfOutPrecision;
BYTE lfClipPrecision;
BYTE lfQuality;
BYTE lfPitchAndFamily;
TCHAR lfFaceName[LF_FACESIZE];
} LOGFONT;
typedef LOGFONT* PLOGFONT ;
typedef LOGFONT* LPLOGFONT ;

//////////////////////////////
// CHOOSEFONT struct
//////////////////////////////
/*UINT (APIENTRY* LPCFHOOKPROC)(
HWND hdlg,
UINT uiMsg,
WPARAM wParam,
LPARAM lParam
);*/
typedef UINT LPCFHOOKPROC;


typedef struct {
DWORD lStructSize;
HWND hwndOwner;
HDC hDC;
LPLOGFONT lpLogFont;
INT iPointSize;
DWORD Flags;
COLORREF rgbColors;
LPARAM lCustData;
/*LPCFHOOKPROC lpfnHook;*/
LPCFHOOKPROC lpfnHook(HWND hdlg,UINT uiMsg,WPARAM wParam,LPARAM lParam);
// function pointer

LPCTSTR lpTemplateName;
HINSTANCE hInstance;
LPTSTR lpszStyle;
WORD nFontType;
INT nSizeMin;
INT nSizeMax;
} CHOOSEFONT;
typedef CHOOSEFONT* PCHOOSEFONT;
typedef CHOOSEFONT* LPCHOOSEFONT;


BOOL WINAPI ChooseFont(CHOOSEFONT* lpcf);
#define PRAGMA_API ChooseFont;comdlg32!ChooseFontA

//////////////////////////////
// Main
//////////////////////////////
void main()
{
wait(-1) ;

CHOOSEFONT cf;
int cyChar;
LOGFONT lf;
TCHAR szText[] = {'1','2','3','4','5'};

GetObject (GetStockObject (SYSTEM_FONT), sizeof (lf), &lf) ;
//printf("%s", lf.lfFaceName);

// Inialize the CHOOSEFONT structure
cf.lStructSize = sizeof (CHOOSEFONT) ;
cf.hwndOwner = NULL ;
cf.hDC = NULL ;
cf.lpLogFont = &lf ;
cf.iPointSize = 0 ;
cf.Flags = CF_INITTOLOGFONTSTRUCT |
CF_SCREENFONTS | CF_EFFECTS ;
cf.rgbColors = 0 ;
cf.lCustData = 0 ;
cf.lpfnHook = NULL ;
cf.lpTemplateName = NULL ;
cf.hInstance = NULL ;
cf.lpszStyle = NULL ;
cf.nFontType = 0 ;
cf.nSizeMin = 0 ;
cf.nSizeMax = 0 ;

ChooseFont (&cf);

}

Thanks in advance, and sorry for my bad english.
Posted By: keilyn3d

Re: How to enum installed (ttf) fonts - 12/09/10 19:13

maybe you don't need it still, but if some one need it:

only change the line:
Code:
WORD nFontType;


to:
Code:
DWORD nFontType;



here is your code repaired:

Code:
#include <acknex.h>
#include <windows.h>
#include <default.c>

typedef char TCHAR;
typedef int INT;
typedef char* LPTSTR;
typedef const char* LPCTSTR;

//////////////////////////////
// LOGFONT struct
//////////////////////////////
typedef struct tagLOGFONT {
LONG lfHeight;
LONG lfWidth;
LONG lfEscapement;
LONG lfOrientation;
LONG lfWeight;
BYTE lfItalic;
BYTE lfUnderline;
BYTE lfStrikeOut;
BYTE lfCharSet;
BYTE lfOutPrecision;
BYTE lfClipPrecision;
BYTE lfQuality;
BYTE lfPitchAndFamily;
TCHAR lfFaceName[LF_FACESIZE];
} LOGFONT;
typedef LOGFONT* PLOGFONT ;
typedef LOGFONT* LPLOGFONT ;

//////////////////////////////
// CHOOSEFONT struct
//////////////////////////////
/*UINT (APIENTRY* LPCFHOOKPROC)(
HWND hdlg,
UINT uiMsg,
WPARAM wParam,
LPARAM lParam
);*/
typedef UINT LPCFHOOKPROC;


typedef struct {
DWORD lStructSize;
HWND hwndOwner;
HDC hDC;
LPLOGFONT lpLogFont;
INT iPointSize;
DWORD Flags;
COLORREF rgbColors;
LPARAM lCustData;
/*LPCFHOOKPROC lpfnHook;*/
LPCFHOOKPROC lpfnHook(HWND hdlg,UINT uiMsg,WPARAM wParam,LPARAM lParam);
// function pointer

LPCTSTR lpTemplateName;
HINSTANCE hInstance;
LPTSTR lpszStyle;
DWORD nFontType;
INT nSizeMin;
INT nSizeMax;
} CHOOSEFONT;
typedef CHOOSEFONT* PCHOOSEFONT;
typedef CHOOSEFONT* LPCHOOSEFONT;


BOOL WINAPI ChooseFont(CHOOSEFONT* lpcf);
#define PRAGMA_API ChooseFont;comdlg32!ChooseFontA

//////////////////////////////
// Main
//////////////////////////////
void main()
{
wait(-1) ;

CHOOSEFONT cf;
int cyChar;
LOGFONT lf;
TCHAR szText[] = {'1','2','3','4','5'};

GetObject (GetStockObject (SYSTEM_FONT), sizeof (lf), &lf) ; 
//printf("%s", lf.lfFaceName);

// Inialize the CHOOSEFONT structure
cf.lStructSize = sizeof (CHOOSEFONT) ;
cf.hwndOwner = NULL ;
cf.hDC = NULL ;
cf.lpLogFont = &lf ;
cf.iPointSize = 0 ;
cf.Flags = CF_INITTOLOGFONTSTRUCT |
CF_SCREENFONTS | CF_EFFECTS ;
cf.rgbColors = 0 ;
cf.lCustData = 0 ;
cf.lpfnHook = NULL ;
cf.lpTemplateName = NULL ;
cf.hInstance = NULL ;
cf.lpszStyle = NULL ;
cf.nFontType = 0 ; 
cf.nSizeMin = 0 ;
cf.nSizeMax = 0 ;

ChooseFont (&cf);

}


© 2024 lite-C Forums