whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

43 Visitors Online


 
...get a TFont's property from a font handle ?
Autor: P. Below
Homepage: http://www.teamb.com
[ Print tip ]  

Tip Rating (4):  
     


uses
  
TypInfo;

function MakeFontFromHFont(aHandle: HFONT): TFONT;
var
  
LogFont: TLogFont;
begin
  
Result := TFont.Create;
  FillChar(LogFont, SizeOf(LogFont), 0);
  GetObject(aHandle, SizeOf(logfont), @LogFont);
  with LogFont, Result do
  begin
    
Name   := StrPas(lffaceName);
    Height := -lfHeight;
    if lfWeight FW_MEDIUM then
      
Style := Style + [fsBold];
    if lfItalic 0 then
      
Style := Style + [fsItalic];
    if lfUnderline 0 then
      
Style := Style + [fsUnderline];
    if lfStrikeout 0 then
      
Style := Style + [fsStrikeout];
    case (lfPitchAndFamily and 3) of
      
VARIABLE_PITCH: Pitch := fpVariable;
      FIXED_PITCH: Pitch    := fpFixed;
    end;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
var
  
f: TFont;
  s: string;
  st: TFontStyle;
begin
  
f := MakeFontfromHFont(getStockObject(ANSI_FIXED_FONT));
  try
    
memo1.Clear;
    with memo1.Lines do
    begin
      
Add(Format('Name: %s', [f.Name]));
      Add(Format('Size: %d', [f.Size]));
      Add(Format('Height: %d', [f.Height]));
      Add(Format('Pitch: %s', [GetEnumName(TypeInfo(TFontPitch),
        Ord(f.Pitch))]));
      S := 'Style: [ ';
      for st := Low(St) to High(st) do
        if 
st in f.Style then
        begin
          
AppendStr(S, GetEnumName(TypeInfo(TFontStyle), Ord(st)));
          AppendStr(S, ' ');
        end;
      AppendStr(S, ']');
      Add(S);
    end;
  finally
    
f.Handle := 0;
    f.Free;
  end;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners