C#控制windows的“拖动时显示窗体内容”系统设置

公司的云桌面,影响到了原生系统的“拖动时显示窗体内容”,做了个处理程序。
感谢AI,现在查资料快速了许多。虽然的确有乱说的成分,但是庆幸的是大体思路没问题。

using System.Runtime.InteropServices;

// 检查当前设置
bool dragFullWindows = MsHelper.GetDragFullWindows();
Console.WriteLine("当前设置: " + (dragFullWindows ? "enable" : "disable"));

// 禁用拖动时显示窗口内容
MsHelper.ChangeDragFullWindows(false);

await Task.Delay(500);

MsHelper.ChangeDragFullWindows(true);

// 再次检查设置
dragFullWindows = MsHelper.GetDragFullWindows();
Console.WriteLine("更改后的设置: " + (dragFullWindows ? "enable" : "disable"));

// 启用拖动时显示窗口内容
//MsHelper.ChangeDragFullWindows(true);

//Console.ReadKey();

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

    //public const uint SPI_GETDRAGFULLWINDOWS = 0x0037;
    //public const uint SPI_SETDRAGFULLWINDOWS = 0x0038;
    public const uint SPI_GETDRAGFULLWINDOWS = 0x0026;
    public const uint SPI_SETDRAGFULLWINDOWS = 0x0025;

    public static bool GetDragFullWindows()
    {
        bool enabled = false;
        SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0, ref enabled, 0);
        return enabled;
    }

    public static void ChangeDragFullWindows(bool enable)
    {
        SystemParametersInfo(SPI_SETDRAGFULLWINDOWS, enable ? 1u : 0, ref enable, SPIF.SPIF_SENDCHANGE);
    }
}

[Flags]
public enum SPIF
{
    SPIF_NONE = 0,
    SPIF_SENDCHANGE = 0x2,
    SPIF_UPDATEINIFILE = 0x1
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章