CreateFontIndirect - 根据字体结构建立逻辑字体
//声明:
CreateFontIndirect(
const p1: TLogFont {字体结构}
): HFONT; {返回新字体指针}
//TLogFont 是 tagLOGFONTA 结构的重定义:
tagLOGFONTA = packed record
lfHeight: Longint; {字体高度}
lfWidth: Longint; {字体平均宽度}
lfEscapement: Longint; {角度, 单位是 1/10 度}
lfOrientation: Longint; {基线角度}
lfWeight: Longint; {粗体, 取值: 0-1000}
lfItalic: Byte; {斜体}
lfUnderline: Byte; {下划线}
lfStrikeOut: Byte; {删除线}
lfCharSet: Byte; {字符集}
lfOutPrecision: Byte; {输出精度}
lfClipPrecision: Byte; {剪裁精度}
lfQuality: Byte; {输出质量}
lfPitchAndFamily: Byte; {间距及字族}
lfFaceName: array[0..LF_FACESIZE - 1] of AnsiChar; {字样名称}
end;
--------------------------------------------------------------------------------
//例1:
procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
FontInfo: TLogFont; {声明字体结构}
FH1,FH2: HFONT; {声明字体句柄}
const
str = '万一的 Delphi 博客';
begin
{定义字体特征}
FontInfo.lfHeight := 0; {赋值 0, 系统自动给一个值}
FontInfo.lfWidth := 0; {赋值 0, 系统自动给一个值}
FontInfo.lfEscapement := 0; {无角度}
FontInfo.lfWeight := 500; {中等加粗}
FontInfo.lfItalic := 0; {非斜体}
FontInfo.lfUnderline := 0; {无下划线}
FontInfo.lfStrikeOut := 0; {无删除线}
FontInfo.lfFaceName := '宋体';
FH1 := CreateFontIndirect(FontInfo);
FH2 := SelectObject(Canvas.Handle, FH1);
{用 CreateFontIndirect 建立逻辑字体; 用 SelectObject 选人设备; 并返回字体句柄}
TextOut(Canvas.Handle, X, Y, str, Length(str));
DeleteObject(FH1);
DeleteObject(FH2);
end;