Проблема заключается в , а не в вашем коде, как вы можете видеть в следующем консольном приложении D2010, меняющем и получающем шрифт и хорошо работающем в 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.