C# 确定当前演示文稿显示模式
由此,我有以下代码将我的演示模式切换为“扩展”: 但我只想在演示文稿显示模式尚未设置为“扩展”时运行该代码段。是否仍然可以通过编程方式确定机器的当前演示显示模式C# 确定当前演示文稿显示模式,c#,winapi,windows-8,multiple-monitors,C#,Winapi,Windows 8,Multiple Monitors,由此,我有以下代码将我的演示模式切换为“扩展”: 但我只想在演示文稿显示模式尚未设置为“扩展”时运行该代码段。是否仍然可以通过编程方式确定机器的当前演示显示模式 注意:该解决方案只需在Windows 8计算机上运行。我不知道您是否仍对解决方案感兴趣。 您必须使用CCD(连接和配置显示器),并且只能通过使用dllimport调用windows函数来实现。 这是到CCD的链接 为此,您必须拨打2个电话。首先,您必须获得缓冲区大小,然后是显示配置 [DllImport("User32.dll")]
注意:该解决方案只需在Windows 8计算机上运行。我不知道您是否仍对解决方案感兴趣。 您必须使用CCD(连接和配置显示器),并且只能通过使用dllimport调用windows函数来实现。 这是到CCD的链接 为此,您必须拨打2个电话。首先,您必须获得缓冲区大小,然后是显示配置
[DllImport("User32.dll")]
public static extern StatusCode GetDisplayConfigBufferSizes(
QueryDisplayConfigFlags flags,
out int numPathArrayElements,
out int numModeInfoArrayElements);
[Flags]
public enum QueryDisplayConfigFlags : uint
{
QDC_ZERO = 0x0,
QDC_ALL_PATHS = 0x00000001,
QDC_ONLY_ACTIVE_PATHS = 0x00000002,
QDC_DATABASE_CURRENT = 0x00000004
}
public enum StatusCode : uint
{
Success = 0,
InvalidParameter = 87,
NotSupported = 50,
AccessDenied = 5,
GenFailure = 31,
BadConfiguration = 1610,
InSufficientBuffer = 122,
}
int numPathArrayElements;
int numModeInfoArrayElements;
var status = CCDWrapper.GetDisplayConfigBufferSizes(
pathType,
out numPathArrayElements,
out numModeInfoArrayElements);
[DllImport("User32.dll")]
public static extern StatusCode QueryDisplayConfig(
QueryDisplayConfigFlags flags,
ref int numPathArrayElements,
[Out] DISPLAYCONFIG_PATH_INFO[] pathInfoArray,
ref int modeInfoArrayElements,
[Out] DisplayConfigModeInfo[] modeInfoArray,
out DISPLAYCONFIG_TOPOLOGY_ID_Flags topologyId
);
[Flags]
public enum DISPLAYCONFIG_TOPOLOGY_ID_Flags: uint
{
DISPLAYCONFIG_TOPOLOGY_ZERO = 0x0,
DISPLAYCONFIG_TOPOLOGY_INTERNAL = 0x00000001,
DISPLAYCONFIG_TOPOLOGY_CLONE = 0x00000002,
DISPLAYCONFIG_TOPOLOGY_EXTEND = 0x00000004,
DISPLAYCONFIG_TOPOLOGY_EXTERNAL = 0x00000008,
DISPLAYCONFIG_TOPOLOGY_FORCE_UINT32 = 0xFFFFFFFF
}
调用中还需要DISPLAYCONFIG\u PATH\u INFO和DisplayConfigModeInfo。它们不能为空。但这两种结构包括其他几种类型,它们太多了,无法粘贴在这里
如果您遵循以下链接,您将在github上找到一个示例项目。
从那里您可以复制缺少的结构。感谢您的努力。我们没有执行检查就发货了。extend feature用例是一个非常小的用例,所以我想它将在优先级列表中非常低,但是如果我设法找到一些时间返回并在以后的版本中尝试一下,我将更新以接受这个答案。
[DllImport("User32.dll")]
public static extern StatusCode GetDisplayConfigBufferSizes(
QueryDisplayConfigFlags flags,
out int numPathArrayElements,
out int numModeInfoArrayElements);
[Flags]
public enum QueryDisplayConfigFlags : uint
{
QDC_ZERO = 0x0,
QDC_ALL_PATHS = 0x00000001,
QDC_ONLY_ACTIVE_PATHS = 0x00000002,
QDC_DATABASE_CURRENT = 0x00000004
}
public enum StatusCode : uint
{
Success = 0,
InvalidParameter = 87,
NotSupported = 50,
AccessDenied = 5,
GenFailure = 31,
BadConfiguration = 1610,
InSufficientBuffer = 122,
}
int numPathArrayElements;
int numModeInfoArrayElements;
var status = CCDWrapper.GetDisplayConfigBufferSizes(
pathType,
out numPathArrayElements,
out numModeInfoArrayElements);
[DllImport("User32.dll")]
public static extern StatusCode QueryDisplayConfig(
QueryDisplayConfigFlags flags,
ref int numPathArrayElements,
[Out] DISPLAYCONFIG_PATH_INFO[] pathInfoArray,
ref int modeInfoArrayElements,
[Out] DisplayConfigModeInfo[] modeInfoArray,
out DISPLAYCONFIG_TOPOLOGY_ID_Flags topologyId
);
[Flags]
public enum DISPLAYCONFIG_TOPOLOGY_ID_Flags: uint
{
DISPLAYCONFIG_TOPOLOGY_ZERO = 0x0,
DISPLAYCONFIG_TOPOLOGY_INTERNAL = 0x00000001,
DISPLAYCONFIG_TOPOLOGY_CLONE = 0x00000002,
DISPLAYCONFIG_TOPOLOGY_EXTEND = 0x00000004,
DISPLAYCONFIG_TOPOLOGY_EXTERNAL = 0x00000008,
DISPLAYCONFIG_TOPOLOGY_FORCE_UINT32 = 0xFFFFFFFF
}