您的位置:首页 > 编程语言 > C#

C#设置双屏显示模式

2014-08-23 23:36 465 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace RecordSystem.Common
{
public static class ScreenHelper
{
private const uint SDC_APPLY = 0x00000080;

private const uint SDC_TOPOLOGY_INTERNAL = 0x00000001;

private const uint SDC_TOPOLOGY_CLONE = 0x00000002;

/// <summary>
/// 扩展模式
/// </summary>
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="displayModel"></param>
/// <returns></returns>
private static bool SetScreen(uint displayModel)
{
return SetDisplayConfig(0, IntPtr.Zero, 0, IntPtr.Zero, SDC_APPLY | displayModel) == 0;
}

/// <summary>
/// 设置屏幕的显示模式
/// </summary>
/// <param name="type">模式(0 - 主屏  1 - 双屏复制  2 - 双屏扩展</param>
/// <returns></returns>
public static bool 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;
default :
smode =  SDC_APPLY | SDC_TOPOLOGY_INTERNAL ;
break;
}

return SetDisplayConfig(0, IntPtr.Zero, 0, IntPtr.Zero, smode) == 0;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息