mol wrote:I'm backing to this topic because I need to get list of fonts installed in system.
I know about function GetFont, but, I need to build my own font selection dialog.
Can anybody help me?
Hi Marek,
Please try the following working sample:
Code: Select all
/*
* HMG - Harbour Win32 GUI library Demo
*
*/
#include "hmg.ch"
Procedure Main()
DEFINE WINDOW Form_Main ;
AT 0,0 ;
WIDTH 640 HEIGHT 480 ;
TITLE 'Main Window' ;
MAIN ;
BACKCOLOR BLUE
DEFINE LABEL Label_1
ROW 205
COL Form_Main.Width - 294
VALUE 'Fonts:'
WIDTH 48
HEIGHT 16
BACKCOLOR BLUE
END LABEL
DEFINE COMBOBOX Combo_1
ROW 200
COL Form_Main.Width - 244
ITEMS GetFonts()
WIDTH 200
VALUE 1
TOOLTIP 'Fonts'
END COMBOBOX
define button Btn_2
row 290
col Form_Main.Width - 234
caption "Cancel"
action Form_Main.Release()
end button
END WINDOW
CENTER WINDOW Form_Main
ACTIVATE WINDOW Form_Main
return
Function GetFonts()
Local aTmp, aFonts := {}, nHandle := GetDC(NIL)
aTmp := GetFontNames( nHandle )
ReleaseDC( NIL, nHandle )
aeval( aTmp, {|e| IF(aScan(aFonts, e) == 0 .and. !"@" $ e, aAdd(aFonts, e), )} )
return aSort(aFonts)
#pragma BEGINDUMP
#define HB_OS_WIN_USED
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include "hbapi.h"
#include "hbapiitm.h"
static far int nFontIndex = 0;
static far BOOL bGetName = FALSE;
HB_FUNC ( GETDC )
{
hb_retnl( (ULONG) GetDC( (HWND) hb_parnl(1) ) ) ;
}
HB_FUNC ( RELEASEDC )
{
hb_retl( ReleaseDC( (HWND) hb_parnl(1), (HDC) hb_parnl(2) ) ) ;
}
// EnumFonts call back routine
static int CALLBACK EnumFontsCallBack( LOGFONT FAR *lpLogFont,
TEXTMETRIC FAR *lpTextMetric, int nFontType , LPARAM lParam )
{
++nFontIndex;
if ( bGetName )
hb_storvc( lpLogFont->lfFaceName, -1, nFontIndex );
return 1;
}
// GetFontNames: Count and return an unsorted array of font names
HB_FUNC ( GETFONTNAMES )
{
FONTENUMPROC lpEnumFontsCallBack = ( FONTENUMPROC )
MakeProcInstance( ( FARPROC ) EnumFontsCallBack, GetModuleHandle( NULL ) );
// Get the number of fonts
nFontIndex = 0;
bGetName = FALSE;
EnumFonts( ( HDC ) hb_parnl( 1 ), NULL, lpEnumFontsCallBack, 0 );
// Get the font names
hb_reta( nFontIndex );
nFontIndex = 0;
bGetName = TRUE;
EnumFonts( ( HDC ) hb_parnl( 1 ), NULL, lpEnumFontsCallBack, 0 );
}
#pragma ENDDUMP
Hope that helps