在Windows7中启用/禁用ClearType

Vit*_*liy 9 registry command-line cleartype windows-7

嗨我需要启用/禁用Cleartype(或"调整Windows的外观和性能>屏幕字体的平滑边缘")通过cmd(或任何脚本,如VBS/JS)或从注册表无需注销或Windows重新启动.

可能只为一个应用程序启用ClearType

谢谢

Jou*_*usi 13

Windows下现代的脚本编写方式是使用PowerShell.以下脚本需要2.0版,可从Windows XP SP3获得:

#requires -version 2.0
param([bool]$enable)

$signature = @'
[DllImport("user32.dll")]
public static extern bool SystemParametersInfo(
    uint uiAction,
    uint uiParam,
    uint pvParam,
    uint fWinIni);
'@

$SPI_SETFONTSMOOTHING      = 0x004B
$SPI_SETFONTSMOOTHINGTYPE  = 0x200B
$SPIF_UPDATEINIFILE        = 0x1
$SPIF_SENDCHANGE           = 0x2
$FE_FONTSMOOTHINGCLEARTYPE = 0x2

$winapi = Add-Type -MemberDefinition $signature -Name WinAPI -PassThru

if ($enable)
{
    [void]$winapi::SystemParametersInfo($SPI_SETFONTSMOOTHING, 1, 0, $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE)
    [void]$winapi::SystemParametersInfo($SPI_SETFONTSMOOTHINGTYPE, 0, $FE_FONTSMOOTHINGCLEARTYPE, $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE)
}
else
{
    [void]$winapi::SystemParametersInfo($SPI_SETFONTSMOOTHING, 0, 0, $SPIF_UPDATEINIFILE -bor $SPIF_SENDCHANGE)
}
Run Code Online (Sandbox Code Playgroud)

如果由于某种原因,您无法使用PowerShell,则需要DynamicWrapperX才能在WSH中执行WinAPI函数.您首先需要在目标计算机上注册它,然后您可以使用此VBScript:

Set WinAPI = CreateObject("DynamicWrapperX")
WinAPI.Register "user32.dll", "SystemParametersInfo", "i=uuuu"

Const SPI_SETFONTSMOOTHING      = &H004B
Const SPI_SETFONTSMOOTHINGTYPE  = &H200B
Const SPIF_UPDATEINIFILE        = &H1
Const SPIF_SENDCHANGE           = &H2
Const FE_FONTSMOOTHINGCLEARTYPE = &H2

If WScript.Arguments(0) Then
    WinAPI.SystemParametersInfo SPI_SETFONTSMOOTHING, 1, 0, SPIF_UPDATEINIFILE Or SPIF_SENDCHANGE
    WinAPI.SystemParametersInfo SPI_SETFONTSMOOTHINGTYPE, 0, FE_FONTSMOOTHINGCLEARTYPE, SPIF_UPDATEINIFILE Or SPIF_SENDCHANGE
Else
    WinAPI.SystemParametersInfo SPI_SETFONTSMOOTHING, 0, 0, SPIF_UPDATEINIFILE Or SPIF_SENDCHANGE
End If
Run Code Online (Sandbox Code Playgroud)

两个脚本都接受一个参数,0表示禁用ClearType,1表示启用.无需重启.

  • @user1306322,`Set-ExecutionPolicy Unrestricted -Force` 应该允许运行所有脚本,但`Set-ExecutionPolicy RemoteSigned` 可能更安全。检查这个:http://stackoverflow.com/questions/4037939/ (2认同)

Car*_*rol 6

只是添加更多选项,我有C#版本,添加GetFontSmoothing.

    [DllImport("user32.dll", SetLastError = true)]
    static extern bool SystemParametersInfo(uint uiAction, uint uiParam, ref int pvParam, uint fWinIni);

    const uint SPI_GETFONTSMOOTHING = 74;
    const uint SPI_SETFONTSMOOTHING = 75;
    const uint SPI_UPDATEINI = 0x1;
    const UInt32 SPIF_UPDATEINIFILE = 0x1;

    private Boolean GetFontSmoothing()
    {
        bool iResult;
        int pv = 0;
        /* Call to systemparametersinfo to get the font smoothing value. */
        iResult = SystemParametersInfo(SPI_GETFONTSMOOTHING, 0, ref pv, 0);
        if (pv > 0)
        {
            //pv > 0 means font smoothing is on.
            return true;
        }
        else
        {
            //pv == 0 means font smoothing is off.
            return false;
        }
    }

    private void DisableFontSmoothing()
    {
        bool iResult;
        int pv = 0;
        /* Call to systemparametersinfo to set the font smoothing value. */
        iResult = SystemParametersInfo(SPI_SETFONTSMOOTHING, 0, ref pv, SPIF_UPDATEINIFILE);
        Console.WriteLine("Disabled: {0}", iResult);
    }

    private void EnableFontSmoothing()
    {
        bool iResult;
        int pv = 0;
        /* Call to systemparametersinfo to set the font smoothing value. */
        iResult = SystemParametersInfo(SPI_SETFONTSMOOTHING, 1, ref pv, SPIF_UPDATEINIFILE);
        Console.WriteLine("Enabled: {0}", iResult);
    }
Run Code Online (Sandbox Code Playgroud)


Nir*_*ond 2

制作带有扩展名的文件。reg这是文件的注册表

禁用屏幕字体的平滑边缘

[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="0"
Run Code Online (Sandbox Code Playgroud)

屏幕字体的启用平滑边缘

[HKEY_CURRENT_USER\Control Panel\Desktop]
"FontSmoothing"="2"
Run Code Online (Sandbox Code Playgroud)

您也可以通过 cmd 执行此操作,这是命令的语法

REG ADD KeyName [/v ValueName | /ve] [/t Type] [/s Separator] [/d Data] [/f]
Run Code Online (Sandbox Code Playgroud)

您必须注销才能使您的更改生效