Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enumerate available fonts
#1
Using this example (most simple example I found)

http://www.catch22.net/tuts/enumfont

I cannot figure out how to work the EnumFontFamiliesEx especially the callback function.

MSDN is not simple enough for me to understand http://msdn.microsoft.com/en-us/library/...S.85).aspx

Function EnumFixedFonts
Code:
Copy      Help
LOGFONT logfont

;ZeroMemory(&logfont, sizeof(logfont));

logfont.lfCharSet = DEFAULT_CHARSET
logfont.lfPitchAndFamily = FIXED_PITCH|FF_DONTCARE
;logfont.lfFaceName = ""
;lstrcpy(logfont.lfFaceName "\0");

int hdc = GetDC(0)

EnumFontFamiliesEx(hdc &logfont &FontNameProc 0 0)
;EnumFontFamiliesEx(hdc &logfont call(&FontNameProc) 0 0)

ReleaseDC(0 hdc)

Function FontNameProc
Code:
Copy      Help
function ENUMLOGFONTEX'&lpelfe NEWTEXTMETRICEX'&lpntme FontType lParam
int i
out "in"
out lpelfe.elfLogFont.lfPitchAndFamily
out lpelfe.elfFullName
if (lpelfe.elfLogFont.lfPitchAndFamily&FIXED_PITCH)
,out "%s" lpelfe.elfFullName
#2
Function EnumFixedFonts
Code:
Copy      Help
out

ARRAY(ENUMLOGFONTEX) a

LOGFONT logfont

logfont.lfCharSet = DEFAULT_CHARSET
logfont.lfPitchAndFamily = FIXED_PITCH|FF_DONTCARE

int hdc = GetDC(0)

EnumFontFamiliesEx(hdc &logfont &FontNameProc &a 0)

ReleaseDC(0 hdc)

int i
for i 0 a.len
,ENUMLOGFONTEX& r=a[i]
,lpstr s=&r.elfLogFont.lfFaceName; out s
,;lpstr s=&r.elfFullName; out s
out a.len

Function FontNameProc
Code:
Copy      Help
;/
function ENUMLOGFONTEX&lpelfe NEWTEXTMETRICEX&lpntme FontType ARRAY(ENUMLOGFONTEX)&a
a[]=lpelfe
ret 1
#3
Error (RT) in EnumFixedFonts: Exception 0xC0000005. Access violation. Cannot read memory at 0x0. In GDI32.dll at 0x7705B770 (0x77040000+0x1B770).
(Points to EnumFontFamiliesEx)
#4
Don't know why.
Maybe memory somewhere is corrupt. As always in such cases, try to create new empty file (with System only), restart QM, create the functions there and test.
#5
Upon restarting QM it worked. Thanks!


Forum Jump:


Users browsing this thread: 1 Guest(s)