微软雅黑字体在没有开启ClearType效果时显示会一塌糊涂,最近项目中因使用了雅黑字体,所以系统启动时候需要自动开启这个功能.
网上大部份资料都是针对注册表的,几乎没有什么用.
相关位置:HKEY_CURRENT_USER\Control Panel\Desktop
类似如下:
if NOT reg.ValueExists('FontSmoothing') then reg.WriteString('FontSmoothing','2');
if NOT reg.ValueExists('FontSmoothingType') then reg.WriteInteger('FontSmoothingType',2);
下面的方法是通过调用SystemParametersInfo来实现:98和2000没有ClearType的功能
使用方法:
Font smoothing is handled by the OS, but can be controlled via the SystemParametersInfo API. Please note that the smoothing type does not apply to Win2K, only XP and above.
// Example usage
const
FE_FONTSMOOTHINGSTANDARD = $00000001;
FE_FONTSMOOTHINGCLEARTYPE = $00000002;
SPI_GETFONTSMOOTHINGTYPE = $0000200A;
SPI_SETFONTSMOOTHINGTYPE = $0000200B;
procedure TForm1.Button1Click(Sender: TObject);
var dwType: DWORD;
bIsSet: BOOL;
begin
if SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, @bIsSet, 0) then
begin
if bIsSet then
begin
ShowMessage('Font smoothing is applied');
if SystemParametersInfo(SPI_GETFONTSMOOTHINGTYPE, 0, @dwType, 0) then
begin
case dwType of
FE_FONTSMOOTHINGSTANDARD : ShowMessage('Smoothing type is standard');
FE_FONTSMOOTHINGCLEARTYPE : ShowMessage('Smoothing type is clear type');
end;
end;
end
else
ShowMessage('Font smoothing not is applied');
end;
// Enable clear type font smoothing
SystemParametersInfo(SPI_SETFONTSMOOTHING, 1, nil, SPIF_UPDATEINIFILE or SPIF_SENDCHANGE);
SystemParametersInfo(SPI_SETFONTSMOOTHINGTYPE, 0, Pointer(FE_FONTSMOOTHINGCLEARTYPE), SPIF_UPDATEINIFILE or SPIF_SENDCHANGE);
// Disable font smoothing
SystemParametersInfo(SPI_SETFONTSMOOTHING, 0, nil, SPIF_UPDATEINIFILE or SPIF_SENDCHANGE);
end;