A: You can use EnumFontFamilies, a Win API function. That uses a callback that is handled each font in turn.
The following sample uses an object method as the callback.
unit Fontenum;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls;
type
TForm1 = class(TForm)
LstFamilies: TListBox;
Label1: TLabel;
Label2: TLabel;
MemVariations: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure LstFamiliesDblClick(Sender: TObject);
private
{ Private declarations }
Function DoEnum( Var lf: TEnumLogFont; Var tm: TNewTextMetric;
fonttype: Integer ): Integer; export;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
Function TForm1.DoEnum( Var lf: TEnumLogFont; Var tm: TNewTextMetric;
fonttype: Integer ): Integer;
Begin
Result := 1;
If (fonttype and TRUETYPE_FONTTYPE) <> 0 Then
Memvariations.Lines.Add( StrPas( lf.elfFullName
))
Else
MemVariations.Lines.Add( StrPas( lf.elfLogFont.lfFacename
));
End;
procedure TForm1.Button1Click(Sender: TObject);
begin
Application.terminate;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
LstFamilies.Items.Assign( Screen.Fonts );
end;
procedure TForm1.LstFamiliesDblClick(Sender: TObject);
Var
familyname: Array [0..40] of Char;
begin
MemVariations.Clear;
With Sender As TListbox Do
If ItemIndex >=0 Then Begin
StrPCopy( familyname, Items[ItemIndex]
);
EnumFontFamilies( Canvas.Handle,
familyname,
@TForm1.DoEnum, Pointer(Self));
End;
end;
end.
-------- form file for this unit ---------
object Form1: TForm1
Left = 310
Top = 229
Width = 497
Height = 300
Caption = 'EnumFontFamilies Demo'
Font.Color = clWindowText
Font.Height = -17
Font.Name = 'System'
Font.Style = []
PixelsPerInch = 120
OnCreate = FormCreate
TextHeight = 20
object Label1: TLabel
Left = 16
Top = 8
Width = 105
Height = 20
Caption = '&Font Families'
FocusControl = LstFamilies
end
object Label2: TLabel
Left = 184
Top = 8
Width = 81
Height = 20
Caption = 'Variations'
end
object LstFamilies: TListBox
Left = 16
Top = 32
Width = 153
Height = 217
ItemHeight = 20
TabOrder = 0
OnDblClick = LstFamiliesDblClick
end
object MemVariations: TMemo
Left = 184
Top = 32
Width = 185
Height = 217
Lines.Strings = (
'')
ReadOnly = True
TabOrder = 1
end
object Button1: TButton
Left = 384
Top = 32
Width = 89
Height = 33
Caption = 'Close'
TabOrder = 2
OnClick = Button1Click
end
end