Learn to build secure applications from the mindset of the hacker and avoid being exploited.
unit CharMap;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Buttons;
type
TCharacterMap = class(TForm)
ComboBox1: TComboBox;
StringGrid1: TStringGrid;
Label1: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure ComboBox1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure WriteText(ACanvas: TCanvas; const ARect: TRect; const Text: string);
public
{ Public declarations }
end;
var
CharacterMap: TCharacterMap;
implementation
{$R *.dfm}
procedure TCharacterMap.ComboBox1Change(Sender: TObject);
var
i, z: Integer;
begin
StringGrid1.Font.Name := ComboBox1.Text;
for z := 0 to 6 do
for i := 0 to 31 do
StringGrid1.Cells[i, z] := Chr((i + 1) * (z + 1) + 31);
end;
(*---------------------------------------------------*)
procedure TCharacterMap.FormCreate(Sender: TObject);
begin
ComboBox1.Items := Screen.Fonts;
ComboBox1.ItemIndex := 0;
ComboBox1Change(ComboBox1);
end;
(*---------------------------------------------------*)
procedure TCharacterMap.StringGrid1DrawCell(Sender: TObject; ACol,
ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
WriteText(StringGrid1.Canvas, Rect, StringGrid1.Cells[acol, arow]);
end;
(*---------------------------------------------------*)
procedure TCharacterMap.WriteText(ACanvas: TCanvas; const ARect: TRect;
const Text: string);
var
S: array[0..255] of Char;
begin
with ACanvas, ARect do
ExtTextOut(Handle, Left + (Right - Left - TextWidth(Text)) div 2, Top + (Bottom - Top - TextHeight(Text)) div 2,
ETO_OPAQUE or ETO_CLIPPED, @ARect, StrPCopy(S, Text), Length(Text), nil);
end;
(*---------------------------------------------------*)
end.
Do more with
function IsTrueTypeFont(FontName : string):boolean;
const
PITCH_MASK: byte = $0F;
var
TxMet: TTextMetric;
TempCanvas : TCanvas;
PitchTest : byte;
begin
TempCanvas:=TCanvas.Create;
TempCanvas.Handle:=CreateCompatibleDC(0) ;
TempCanvas.Font.Name:=FontName;
GetTextMetrics(TempCanvas.Handle, TxMet) ;
PitchTest:=TxMet.tmPitchAndFamily and PITCH_MASK;
Result:=(PitchTest and TMPF_TRUETYPE) <> 0;
TempCanvas.free;
end;
procedure TForm1.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
With (Control As TComboBox).Canvas do
begin
Draw(Rect.Left+2,Rect.Top+2,BMP);
TextOut(Rect.Left+32,Rect.Top+2,TComboBox(Control).Items[Index]);
end;
end;
Premium Content
You need an Expert Office subscription to comment.Start Free Trial