Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than gdi32, prefix the name with the module name and a period.
int ret = 0;
try
{
//If anyone knows of a better way to get the pointer please let me know
var pictureBox = new PictureBox();
var graphic = pictureBox.CreateGraphics();
var ptr = graphic.GetHdc();
del1 = new EnumFontExDelegate(callback1);
ret = EnumFontFamiliesEx(ptr, plogFont, del1, IntPtr.Zero, 0);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public class LOGFONT
{
public int lfHeight;
public int lfWidth;
public int lfEscapement;
public int lfOrientation;
public FontWeight lfWeight;
[MarshalAs(UnmanagedType.U1)]
public bool lfItalic;
[MarshalAs(UnmanagedType.U1)]
public bool lfUnderline;
[MarshalAs(UnmanagedType.U1)]
public bool lfStrikeOut;
public FontCharSet lfCharSet;
public FontPrecision lfOutPrecision;
public FontClipPrecision lfClipPrecision;
public FontQuality lfQuality;
public FontPitchAndFamily lfPitchAndFamily;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string lfFaceName;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NEWTEXTMETRIC
{
public int tmHeight;
public int tmAscent;
public int tmDescent;
public int tmInternalLeading;
public int tmExternalLeading;
public int tmAveCharWidth;
public int tmMaxCharWidth;
public int tmWeight;
public int tmOverhang;
public int tmDigitizedAspectX;
public int tmDigitizedAspectY;
public char tmFirstChar;
public char tmLastChar;
public char tmDefaultChar;
public char tmBreakChar;
public byte tmItalic;
public byte tmUnderlined;
public byte tmStruckOut;
public byte tmPitchAndFamily;
public byte tmCharSet;
int ntmFlags;
int ntmSizeEM;
int ntmCellHeight;
int ntmAvgWidth;
}
public struct FONTSIGNATURE
{
[MarshalAs(UnmanagedType.ByValArray)]
int[] fsUsb;
[MarshalAs(UnmanagedType.ByValArray)]
int[] fsCsb;
}
public struct NEWTEXTMETRICEX
{
NEWTEXTMETRIC ntmTm;
FONTSIGNATURE ntmFontSig;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct ENUMLOGFONTEX
{
public LOGFONT elfLogFont;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string elfFullName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string elfStyle;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string elfScript;
}
public delegate int EnumFontExDelegate(ref ENUMLOGFONTEX lpelfe, ref NEWTEXTMETRICEX lpntme, int FontType, int lParam);
public EnumFontExDelegate del1;
public int callback1(ref ENUMLOGFONTEX lpelfe, ref NEWTEXTMETRICEX lpntme, int FontType, int lParam)
{
try
{
FontType fontType;
if (FontType == 2 || FontType == 4)
{
fontType = (ClientTools.Fonts.FontType)FontType;
}
else
{
fontType = ClientTools.Fonts.FontType.Unknown;
}
public const Int32 LF_FACESIZE = 32; // ref WinGDI.h
public const Int32 LF_FULLFACESIZE = 64; // ref WinGDI.h
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct LOGFONT
{
public Int32 lfHeight;
public Int32 lfWidth;
public Int32 lfEscapement;
public Int32 lfOrientation;
public Int32 lfWeight;
public Byte lfItalic;
public Byte lfUnderline;
public Byte lfStrikeOut;
public Byte lfCharSet;
public Byte lfOutPrecision;
public Byte lfClipPrecision;
public Byte lfQuality;
public Byte lfPitchAndFamily;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = LF_FACESIZE)]
public String lfFaceName;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct TEXTMETRIC
{
public Int32 tmHeight;
public Int32 tmAscent;
public Int32 tmDescent;
public Int32 tmInternalLeading;
public Int32 tmExternalLeading;
public Int32 tmAveCharWidth;
public Int32 tmMaxCharWidth;
public Int32 tmWeight;
public Int32 tmOverhang;
public Int32 tmDigitizedAspectX;
public Int32 tmDigitizedAspectY;
public Char tmFirstChar;
public Char tmLastChar;
public Char tmDefaultChar;
public Char tmBreakChar;
public Byte tmItalic;
public Byte tmUnderlined;
public Byte tmStruckOut;
public Byte tmPitchAndFamily;
public Byte tmCharSet;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct ENUMLOGFONT
{
public LOGFONT elfLogFont;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = LF_FULLFACESIZE)]
public String elfFullName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = LF_FACESIZE)]
public String elfStyle;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct NEWTEXTMETRIC
{
public Int32 tmHeight;
public Int32 tmAscent;
public Int32 tmDescent;
public Int32 tmInternalLeading;
public Int32 tmExternalLeading;
public Int32 tmAveCharWidth;
public Int32 tmMaxCharWidth;
public Int32 tmWeight;
public Int32 tmOverhang;
public Int32 tmDigitizedAspectX;
public Int32 tmDigitizedAspectY;
public Char tmFirstChar;
public Char tmLastChar;
public Char tmDefaultChar;
public Char tmBreakChar;
public Byte tmItalic;
public Byte tmUnderlined;
public Byte tmStruckOut;
public Byte tmPitchAndFamily;
public Byte tmCharSet;
public UInt32 ntmFlags;
public UInt32 ntmSizeEM;
public UInt32 ntmCellHeight;
public UInt32 ntmAvgWidth;
}
public struct FontData
{
public ENUMLOGFONT LogFont;
public NEWTEXTMETRIC TextMetric;
public uint FontType;
}
private static List<FontData> allFontData;
public static List<FontData> GetAllFonts()
{
allFontData = new List<FontData>();
Graphics graphics = Graphics.FromHwnd(IntPtr.Zero);
try
{
IntPtr hdc = graphics.GetHdc();
var logfont = new LOGFONT() { lfCharSet = (byte)FontLanguageCharSet.DEFAULT_CHARSET };
EnumFontFamiliesEx(hdc, ref logfont, new FONTENUMPROC(EnumFontFamExProc), IntPtr.Zero, 0);
}
catch (Exception)
{
}
finally
{
graphics.ReleaseHdc();
}
return allFontData;
}
}
Use the GetAllFonts method to load all information about installed fonts. Returns List<FontData> which you can use Linq to query.
Sample Code:
C#:
class Program
{
static void Main(string[] args)
{
List<GdiFonts.FontData> allFonts = GdiFonts.GetAllFonts();
// Fixed Pitch & ANSI_CHARSET
List<string> mono = (from f in allFonts where ((f.LogFont.elfLogFont.lfPitchAndFamily & 0x3) == (int)GdiFonts.FontPitch.FIXED_PITCH) & (GdiFonts.FontLanguageCharSet)f.LogFont.elfLogFont.lfCharSet == GdiFonts.FontLanguageCharSet.ANSI_CHARSET select f.LogFont.elfFullName).ToList<string>();
// Variable Pitch & ANSI_CHARSET
List<string> variable = (from f in allFonts where ((f.LogFont.elfLogFont.lfPitchAndFamily & 0x3) == (int)GdiFonts.FontPitch.VARIABLE_PITCH) & (GdiFonts.FontLanguageCharSet)f.LogFont.elfLogFont.lfCharSet == GdiFonts.FontLanguageCharSet.ANSI_CHARSET select f.LogFont.elfFullName).ToList<string>();
Console.Read();
}
}
The EnumFontFamiliesEx API
11/7/2015 6:20:13 AM - -94.230.89.241
The EnumFontFamiliesEx API
11/7/2015 6:39:16 AM - -134.223.116.154
The LOGFONT structure defines the attributes of a font.
11/3/2015 6:42:15 PM - -194.25.158.132
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).