Click here to Skip to main content
15,905,008 members
Home / Discussions / C#
   

C#

 
QuestionHow to implement Zooming? Pin
blankg22-Jul-04 5:18
blankg22-Jul-04 5:18 
AnswerRe: How to implement Zooming? Pin
Anonymous22-Jul-04 5:33
Anonymous22-Jul-04 5:33 
QuestionCrystal Report Viewer do not show box object rounded? Pin
Anonymous22-Jul-04 3:33
Anonymous22-Jul-04 3:33 
AnswerRe: Crystal Report Viewer do not show box object rounded? Pin
Heath Stewart22-Jul-04 5:10
protectorHeath Stewart22-Jul-04 5:10 
GeneralBrowser Helper Objects Pin
Stuggo22-Jul-04 3:11
Stuggo22-Jul-04 3:11 
GeneralRe: Browser Helper Objects Pin
mav.northwind22-Jul-04 3:47
mav.northwind22-Jul-04 3:47 
GeneralRe: Browser Helper Objects Pin
Heath Stewart22-Jul-04 5:03
protectorHeath Stewart22-Jul-04 5:03 
GeneralRe: Browser Helper Objects Pin
mav.northwind22-Jul-04 5:49
mav.northwind22-Jul-04 5:49 
GeneralRe: Browser Helper Objects Pin
Stuggo22-Jul-04 8:49
Stuggo22-Jul-04 8:49 
GeneralInstalation Pin
thomasa22-Jul-04 0:40
thomasa22-Jul-04 0:40 
GeneralRe: Instalation Pin
OBRon22-Jul-04 5:26
OBRon22-Jul-04 5:26 
GeneralRe: Instalation Pin
Heath Stewart22-Jul-04 5:50
protectorHeath Stewart22-Jul-04 5:50 
GeneralRe: Instalation Pin
Heath Stewart22-Jul-04 5:40
protectorHeath Stewart22-Jul-04 5:40 
GeneralDCOM replacement in .NET Pin
Muhammad Ahmed21-Jul-04 23:17
Muhammad Ahmed21-Jul-04 23:17 
GeneralRe: DCOM replacement in .NET Pin
mav.northwind21-Jul-04 23:35
mav.northwind21-Jul-04 23:35 
GeneralRe: DCOM replacement in .NET Pin
Muhammad Ahmed22-Jul-04 1:09
Muhammad Ahmed22-Jul-04 1:09 
GeneralRe: DCOM replacement in .NET Pin
mav.northwind22-Jul-04 2:00
mav.northwind22-Jul-04 2:00 
General(OT?): webservice credentials Pin
Stephan Wright21-Jul-04 21:30
Stephan Wright21-Jul-04 21:30 
GeneralRe: (OT?): webservice credentials Pin
Heath Stewart22-Jul-04 4:56
protectorHeath Stewart22-Jul-04 4:56 
QuestionFetching Font information ? Pin
sachinkalse21-Jul-04 21:02
sachinkalse21-Jul-04 21:02 
AnswerRe: Fetching Font information ? Pin
Heath Stewart22-Jul-04 4:41
protectorHeath Stewart22-Jul-04 4:41 
GeneralRe: Fetching Font information ? Pin
sachinkalse22-Jul-04 14:50
sachinkalse22-Jul-04 14:50 
GeneralRe: Fetching Font information ? Pin
Heath Stewart23-Jul-04 5:27
protectorHeath Stewart23-Jul-04 5:27 
D'Oh! | :doh: Sorry 'bout that. Wasn't really thinking much about it.

If that's not working the way you expect it, I'd seriously take another look at the code surrounding EnumFontFamilies(Ex). Be sure to read the docs in the Platform SDK if you haven't already.

Here's an example I threw together quick that works fine:
using System;
using System.Runtime.InteropServices;

class EnumFonts
{
  static void Main(string[] args)
  {
    string family = null;
    if (args.Length > 0) family = args[0];

    // Get the HDC for the desktop.
    IntPtr hdc = GetDC(IntPtr.Zero);

    try
    {
      EnumFontFamilies(hdc, family,
        new EnumFontFamProc(Callback), IntPtr.Zero);
    }
    catch (Exception ex)
    {
      Console.Error.WriteLine("There was an error enumerating the " +
        "font families: " + ex.Message);
    }
    finally
    {
      ReleaseDC(IntPtr.Zero, hdc);
    }
  }

  static IntPtr Callback(ref ENUMLOGFONT font, ref NEWTEXTMETRIC metric,
    int fontType, IntPtr lParam)
  {
    Console.WriteLine(font.FullName);
    return new IntPtr(1); // Continue enumeration.
  }

  [DllImport("user32.dll")]
  static extern IntPtr GetDC(IntPtr hWnd);

  [DllImport("user32.dll")]
  static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);

  [DllImport("gdi32.dll", CharSet=CharSet.Auto)]
  static extern IntPtr EnumFontFamilies(
    IntPtr hdc,
    string family,
    EnumFontFamProc proc,
    IntPtr lParam);

  delegate IntPtr EnumFontFamProc(
    ref ENUMLOGFONT font,
    ref NEWTEXTMETRIC metric,
    [MarshalAs(UnmanagedType.U4)] int fontType,
    IntPtr lParam);

  [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
  struct LOGFONT
  {
    public int Height;
    public int Width;
    public int Escapement;
    public int Orientation;
    public int Weight;
    public byte Italic;
    public byte Underline;
    public byte StrikeOut;
    public byte CharSet;
    public byte OutPrecision;
    public byte ClipPrecision;
    public byte Quality;
    public byte PitchAndFamily;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
      public string FaceName;
  }

  [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
  struct ENUMLOGFONT
  {
    public LOGFONT LogFont;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)]
      public string FullName;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)]
      public string Style;
  }

  [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
  struct NEWTEXTMETRIC // Also TEXTMETRIC for non-TrueType fonts
  {
    public int Height;
    public int Ascent;
    public int Descent;
    public int InternalLeading;
    public int ExternalLeading;
    public int AveCharWidth;
    public int MaxCharWidth;
    public int Weight;
    public int Overhang;
    public int DigitizedAspectX;
    public int DigitizedAspectY;
    public char FirstChar;
    public char Lastchar;
    public char DefaultChar;
    public char BreakChar;
    public byte Italic;
    public byte Underlined;
    public byte StruckOut;
    public byte PitchAndFamily;
    public byte CharSet; // TEXTMETRIC ends here
    [MarshalAs(UnmanagedType.U4)] public int Flags;
    [MarshalAs(UnmanagedType.SysUInt)] public IntPtr SizeEM;
    [MarshalAs(UnmanagedType.SysUInt)] public IntPtr CellHeight;
    [MarshalAs(UnmanagedType.SysUInt)] public IntPtr AvgWidth;
  }
}


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Fetching Font information ? Pin
sachinkalse25-Jul-04 16:41
sachinkalse25-Jul-04 16:41 
GeneralRe: Fetching Font information ? Pin
Heath Stewart26-Jul-04 4:38
protectorHeath Stewart26-Jul-04 4:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.