getcharabcwidthsu.pas

来自「Delphi Win32核心API参考光盘源码 本书包含了常用的Windows」· PAS 代码 · 共 53 行

PAS
53
字号
unit GetCharABCWidthsU;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Label1: TLabel;
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormActivate(Sender: TObject);
var
  CharWidths: array[0..25]of TABC;   // holds character ABC widths
  Count: Integer;                    // general loop control variable
begin
  {initialize the string grid}
  StringGrid1.Cells[0,0] := 'Character';
  StringGrid1.Cells[1,0] := '''A'' Width';
  StringGrid1.Cells[2,0] := '''B'' Width';
  StringGrid1.Cells[3,0] := '''C'' Width';

  {retrieve ABC widths for all upper case letters}
  GetCharABCWidths(Form1.Canvas.Handle, Ord('A'), Ord('Z'), CharWidths);

  {display the ABC widths for all uppercase letters}
  for Count := 0 to 26 do
  begin
    StringGrid1.Cells[0, Count+1] := Char(Ord('A')+Count);
    StringGrid1.Cells[1, Count+1] := IntToStr(CharWidths[Count].abcA);
    StringGrid1.Cells[2, Count+1] := IntToStr(CharWidths[Count].abcB);
    StringGrid1.Cells[3, Count+1] := IntToStr(CharWidths[Count].abcC);
  end;
end;


end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?