简体   繁体   English

确定当前演示显示模式

[英]Determine Current Presentation Display Mode

Taken from this SO question I have the following code that switches my presentation mode to "extend": 出于这个问题,我有以下代码将演示模式切换为“扩展”:

var proc = new Process { StartInfo = { FileName = "DisplaySwitch.exe", Arguments = "/extend" } };
proc.Start();

But I only want to run that snippet if the presentation display mode isn't already set to extend. 但是我只想在演示文稿显示模式尚未设置为扩展的情况下运行该代码段。 Is there anyway to programmatically determine the current presentation display mode of a machine? 无论如何,是否可以通过编程确定机器的当前演示显示模式

Note: The solution only needs to work for Windows 8 machines. 注意:该解决方案仅需要在Windows 8计算机上工作。

I don't know if you are still interested in a solution. 我不知道您是否仍然对解决方案感兴趣。 You have to make use of CCD (Connecting and Configuring Displays) and you can only do that by calling windows functions with dllimport. 您必须使用CCD(连接和配置显示器),并且只能通过使用dllimport调用Windows函数来实现。 Here is the Link to CCD https://msdn.microsoft.com/en-us/library/windows/hardware/ff539367(v=vs.85).aspx 这是CCD的链接https://msdn.microsoft.com/en-us/library/windows/hardware/ff539367(v=vs.85).aspx

For this, you have to make 2 calls. 为此,您必须拨打2个电话。 First you have to get the buffer size and then the display config. 首先,您必须获取缓冲区大小,然后获取显示配置。

[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_PATH_INFO and DisplayConfigModeInfo are also needed in the call. 调用中还需要DISPLAYCONFIG_PATH_INFO和DisplayConfigModeInfo。 They cannot be null. 它们不能为null。 But these two structures include several other types which is too much to paste here. 但是,这两个结构还包含其他几种类型,因此无法在此处粘贴。

If you follow the following link you find a sample project on github. 如果您点击以下链接,则会在github上找到一个示例项目。 droid-autorotate@Github 机器人,自动旋转@ Github上

From there you can copy the missing structures. 从那里可以复制丢失的结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM