EnumFonts

Z

ZaRMaS

Hi all,

I'm using GDI to enumerate fonts (installed or not in system) with
function EnumFonts.

My source :
AddFontResourceEx(@"C:\essai\FontTest.otf", FR_PRIVATE, IntPtr.Zero);
It returns 1 so the font is now isntalled and I send message :


SendMessage(HWND_BROADCAST, WM_FONTCHANGE, IntPtr.Zero, IntPtr.Zero);

I initialize my callback function and I create a DC

EnumFontExDelegate myefd = new EnumFontExDelegate(callback);
IntPtr dc = CreateDC("DISPLAY", null, null, IntPtr.Zero);
EnumFonts(dc, null, myefd, IntPtr.Zero);

My callback function declaration :
private int callback(ref ENUMLOGFONTEX lpelfe, IntPtr lpntme, int
FontType, int lParam)
{
return 1; //If it's 0 the callback function is called just one time
}

At this moment, my function callback is called for each font installed
(and added).
My problem is that lpelfe.elfFullName.ToString() is not empty, but it
returns "?↑?" for each fonts.

What have done wrong ?


Thank you for your help
 
N

Nicholas Paldino [.NET/C# MVP]

First, what is your declaration of AddFontResourceEx?

Second, the documentation for EnumFonts states:

The EnumFonts function enumerates the fonts available on a specified device.

That being said, you are creating a display device context, which means
that most of the fonts on the system should be available to you. This is
why your callback is being called multiple times.

My assumption is that you declared the EnumFonts function wrong, and it
is an encoding issue.

Post your declarations.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi all,

I'm using GDI to enumerate fonts (installed or not in system) with
function EnumFonts.

My source :
AddFontResourceEx(@"C:\essai\FontTest.otf", FR_PRIVATE, IntPtr.Zero);
It returns 1 so the font is now isntalled and I send message :


SendMessage(HWND_BROADCAST, WM_FONTCHANGE, IntPtr.Zero, IntPtr.Zero);

I initialize my callback function and I create a DC

EnumFontExDelegate myefd = new EnumFontExDelegate(callback);
IntPtr dc = CreateDC("DISPLAY", null, null, IntPtr.Zero);
EnumFonts(dc, null, myefd, IntPtr.Zero);

My callback function declaration :
private int callback(ref ENUMLOGFONTEX lpelfe, IntPtr lpntme, int
FontType, int lParam)
{
return 1; //If it's 0 the callback function is called just one time
}

At this moment, my function callback is called for each font installed
(and added).
My problem is that lpelfe.elfFullName.ToString() is not empty, but it
returns "???" for each fonts.

What have done wrong ?


Thank you for your help
 
Z

ZaRMaS

My declaration :
[DllImport("gdi32.dll")]
static extern int EnumFonts(IntPtr hdc, string lpFaceName,
EnumFontExDelegate
lpFontFunc, IntPtr lParam);
 
N

Nicholas Paldino [.NET/C# MVP]

Try this:

[DllImport("gdi32.dll", CharSet=CharSet.Auto)]
static extern int EnumFonts(IntPtr hdc, string lpFaceName,
EnumFontExDelegate lpFontFunc, IntPtr lParam);

Also, you might want to try the InstalledFontCollection class in the
System.Drawing.Text namespace, as it will give you a list of installed
fonts.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top