shigure
private const uint SDC_APPLY = 0x00000080;

private const uint SDC_TOPOLOGY_INTERNAL = 0x00000001;

private const uint SDC_TOPOLOGY_CLONE = 0x00000002;

private const uint SDC_TOPOLOGY_EXTERNAL = 0x00000008;

private const uint SDC_TOPOLOGY_EXTEND = 0x00000004;

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern long SetDisplayConfig(uint numPathArrayElements, IntPtr pathArray, uint numModeArrayElements, IntPtr modeArray, uint flags);

/// <summary>
/// 设置屏幕的显示模式
/// </summary>
/// <param name="type">模式(0 - 主屏  1 - 双屏复制  2 - 双屏扩展  3 - 第二屏幕</param>
/// <returns></returns>
public static void SetScreenMode(int type)
{
    uint smode;

    switch (type)
    {
        case 0:
            smode = SDC_APPLY | SDC_TOPOLOGY_INTERNAL;
            break;
        case 1:
            smode = SDC_APPLY | SDC_TOPOLOGY_CLONE;
            break;
        case 2:
            smode = SDC_APPLY | SDC_TOPOLOGY_EXTEND;
            break;
        case 3:
            smode = SDC_APPLY | SDC_TOPOLOGY_EXTERNAL;
            break;
        default:
            smode = SDC_APPLY | SDC_TOPOLOGY_INTERNAL;
            break;
    }

    SetDisplayConfig(0, IntPtr.Zero, 0, IntPtr.Zero, smode);
}

当屏幕选择了单屏幕显示或者双屏复制时,Screen.AllScreens.Length只会返回1,只有双屏幕复制时才会返回2。

参考:https://www.cnblogs.com/zzr-stdio/p/12093159.html

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-11-12
  • 2021-11-01
  • 2021-06-25
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2021-11-23
  • 2021-09-10
  • 2021-07-15
  • 2021-11-06
相关资源
相似解决方案