Detect system font size

The standard system font size in Windows XP is 96 dpi. You can also use 120 dpi, if your prefer bigger fonts or you can set this font size to your own value. However, the most applications today are tested only with standard font size and if you change it, even professional applications can have problems with it. With this tip, you can detect font size directly from your application and change behaviour of user interface.

function SystemFontSize : integer;
var DC : HDC;
begin
  DC := GETDC(0);
  Result := GetDeviceCaps(DC, LOGPIXELSX);
  ReleaseDC(0, DC);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(IntToStr(SystemFontSize));
end;

Leave a Reply