在Windows7中启用/禁用ClearType

| 你好 我需要通过cmd(或任何VBS / JS之类的脚本)或从注册表中启用/禁用Cleartype(或“调整Windows的外观和性能>屏幕字体的平滑边缘”),或者从注册表中启用/禁用,而无需注销或重新启动Windows。 可能只为一个应用程序启用ClearType 谢谢     
已邀请:
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)
}
如果由于某种原因不能使用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
这两个脚本都接受一个参数,“ 2”表示禁用ClearType,“ 3”表示启用。无需重新启动。     
为了添加更多选项,我使用了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);
    }
    
Python版本:
# make sure you install pywin32 
# from http://sourceforge.net/projects/pywin32/files/pywin32/Build%20218/
import win32con
import win32gui

win32gui.SystemParametersInfo(win32con.SPI_SETFONTSMOOTHING, True, 0) # enable only
win32gui.SystemParametersInfo(win32con.SPI_SETFONTSMOOTHINGTYPE,
        win32con.FE_FONTSMOOTHINGCLEARTYPE,
        win32con.SPIF_UPDATEINIFILE | win32con.SPIF_SENDCHANGE)
    
使文件具有扩展名。
reg
这是文件的注册表 Disable_Smooth_edges_of_screen_fonts
[HKEY_CURRENT_USER\\Control Panel\\Desktop]
\"FontSmoothing\"=\"0\"
Enable_Smooth_edges_of_screen_fonts
[HKEY_CURRENT_USER\\Control Panel\\Desktop]
\"FontSmoothing\"=\"2\"
你也可以这样做 这是命令的语法
REG ADD KeyName [/v ValueName | /ve] [/t Type] [/s Separator] [/d Data] [/f]
您必须注销才能使更改生效     
我不知道如何重新启动... 但是我发现仅更改FontSmoothing键是不够的... 有关如何完全删除ClearType和FontSmoothing的完整过程,请查看以下内容: Completley在Windows 7中禁用字体平滑和ClearType     
以下对我有用: 控制面板>系统>高级系统设置>高级>(性能)设置>视觉效果>选择\'自定义\',然后取消选中\'屏幕字体的平滑边缘\'     
查看以下链接中描述的内容: http://www.vbforums.com/showthread.php?t=491091 调用API可能会触发系统范围的更新,因此您无需注销/登录即可查看更改。 当然,这不限于vb.net。     
这是执行此操作的PowerShell方法:
Set-ItemProperty \'HKCU:\\Control Panel\\Desktop\\\' -Name FontSmoothing -Value \"2\"
您需要注销然后重新登录才能生效。   注意:奇怪的是,该设置未在“性能”中显示为已启用   选项,即使它已明确打开:     

要回复问题请先登录注册