views:

116

answers:

2

I am currently using the function SystemParametersInfo to retrieve SPI_GETICONTITLELOGFONT. According to the MSDN documentation this is the http://msdn.microsoft.com/en-us/library/ms724947(VS.85).aspx

"Retrieves the logical font information for the current icon-title font"

But this always retrieves 'Segoe UI' even when I change my font to 'VivlaidD'. I am on a Windows 7 machine. Is it that this function only retrieves the system default? Or is there something wrong with 'SystemParametersInfo'?

Here is my code for retrieving the font:

procedure GetUserFontPreference(out FaceName: string; out PixelHeight: Integer);
var
  lf: LOGFONT;
begin
  ZeroMemory(@lf, SizeOf(lf));

  if SystemParametersInfo(SPI_GETICONTITLELOGFONT, SizeOf(lf), @lf, 0) then
  begin
    FaceName := PChar(Addr(lf.lfFaceName[0]));
    PixelHeight := lf.lfHeight;
  end
  else
  begin
    {
            If we can't get it, then assume the same non-user preferences that
            everyone else does.
    }
    FaceName := 'MS Shell Dlg 2';
    PixelHeight := 8;
  end;
end;
A: 

May be you change the wrong font in Personalization menu? If I change the Icon font from Segoe UI to Verdana, the following code works properly:

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows;

var
  LogFont: TLogFont;

begin
  try
    if SystemParametersInfo(SPI_GETICONTITLELOGFONT, SizeOf(LogFont),
      @LogFont, 0) then
      Writeln('Current Font is ', LogFont.lfFaceName)
    else
      Writeln('Error #', GetLastError);

    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
Keeper
I also thought I might have changed the wrong font so what I did was change all my fonts to VivaldiD, but I still could only get 'Segoe UI'.
Ren
And my code doesn't work either?
Keeper
I edited my original post and as you can see it is almost identical, but technically speaking, no I did not try your code.
Ren
A: 

The problem is not with your code as you can see with the following D2010 console app, changing and retrieving the font, and working well on Win7 x64:

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils, Windows;


procedure GetUserFontPreference(out FaceName: string; out PixelHeight: Integer);
var
  lf: LOGFONT;
begin
  ZeroMemory(@lf, SizeOf(lf));

  if SystemParametersInfo(SPI_GETICONTITLELOGFONT, SizeOf(lf), @lf, 0) then
  begin
    FaceName := lf.lfFaceName; // simpler than PChar(Addr(lf.lfFaceName[0]));
    PixelHeight := lf.lfHeight;
  end
  else
  begin
    {
            If we can t get it, then assume the same non-user preferences that
            everyone else does.
    }
    FaceName := 'MS Shell Dlg 2';
    PixelHeight := 8;
  end;
end;

procedure SetUserFontPreference(const AFaceName: string; const APixelHeight: Integer);
var
  lf: LOGFONT;
begin
  ZeroMemory(@lf, SizeOf(lf));
  Move(AFaceName[1], lf.lfFaceName, Length(AFaceName)*SizeOf(Char));
  lf.lfHeight := APixelHeight;
  SystemParametersInfo(SPI_SETICONTITLELOGFONT, SizeOf(lf), @lf, 0);
end;

procedure Test;
var
  FontName, NewFontName, OldFontName: string;
  FontHeight: Integer;
begin
  GetUserFontPreference(OldFontName, FontHeight);
  Writeln('Current (Old) Font is ', OldFontName);
  Readln;

  NewFontName := 'Rage Italic';  //'Segoe UI';//'Rage Italic';
  SetUserFontPreference(NewFontName, FontHeight);
  GetUserFontPreference(FontName, FontHeight);
  Assert(FontName=NewFontName);
  Writeln('Current (New) Font is ', FontName);
  Readln;

  SetUserFontPreference(OldFontName, FontHeight);
  GetUserFontPreference(FontName, FontHeight);
  Assert(FontName=OldFontName);
  Writeln('Current Font is back to (Old) ', FontName);
  Readln;
end;

begin
  try
    Test;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
François