把字体保存到注册表或流中

时间:2010-03-07 14:00:46  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:e FontRec = packed record Color: TColor; LogFont: TLogFont; end; // Save a font to the registry 保存到注册表procedure SaveFontToReg(reg: TRegistry; const key, id: string; Font: TFont); var fRec: FontRec; begin   if Windows.GetObject(Font.Handle, SizeOf(fRec.LogFont), @fRec.Log...
  正文:本站以前曾有过这方面的文章,这是我从国外网站上找的,方法差不多,比较实用.


type
FontRec = packed record
Color: TColor;
LogFont: TLogFont;
end;

// Save a font to the registry 保存到注册表
procedure SaveFontToReg(reg: TRegistry; const key, id: string; Font: TFont);
var
fRec: FontRec;
begin
  if Windows.GetObject(Font.Handle, SizeOf(fRec.LogFont), @fRec.LogFont) > 0 then
  begin
    if reg.OpenKey(key, True) then
    try
      fRec.Color := Font.Color;
      reg.WriteBinaryData(id, fRec, SizeOf(fRec));
      finally
        reg.CloseKey;
      end;
    end;
  end;
  
  // Load a font from the registry 读取注册表
procedure LoadFont(reg: TRegistry; const key, id: string; Font: TFont);
  var
  fRec: FontRec;
  begin
    if reg.OpenKey(key, False) then
    try
      if reg.ReadBinaryData(id, frec, SizeOf(fRec)) = SizeOf(fRec) then
      Font.Handle := CreateFontIndirect(fRec.LogFont);
      Font.Color := fRec.Color;
      finally
        reg.CloseKey;
      end;
    end;
    
    // Save a font to a stream 保存到流
procedure WriteFontToStream(s: TStream; Font: TFont);
    var
    fRec: FontRec;
    sz: integer;
    begin
      sz := SizeOf(fRec.LogFont);
      if Windows.GetObject(Font.Handle, sz, @fRec.LogFont) > 0 then
      begin
        s.Write(sz, SizeOf(Integer));
        fRec.Color := Font.Color;
        s.Write(fRec, SizeOf(fRec));
      end
      else
      begin
        sz := 0;
        s.Write(sz, SizeOf(Integer));
      end;
    end;
    
    // Read a font from a stream 从流中读出
procedure ReadFont(s: TStream; Font: TFont);
    var
    fRec: FontRec;
    sz: integer;
    begin
      s.read(sz, SizeOf(Integer));
      if sz = SizeOf(fRec.LogFont) then
      begin
        s.read(fRec, SizeOf(fRec));
        Font.Handle := CreateFontIndirect(fRec.LogFont);
        Font.Color  := fRec.Color;
      end;
    end;
    
"把字体保存到注册表或流中"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/13104.html


关键字:

关于《把字体保存到注册表或流中》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td