簡體   English   中英

確定當前演示顯示模式

[英]Determine Current Presentation Display Mode

出於這個問題,我有以下代碼將演示模式切換為“擴展”:

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

但是我只想在演示文稿顯示模式尚未設置為擴展的情況下運行該代碼段。 無論如何,是否可以通過編程確定機器的當前演示顯示模式

注意:該解決方案僅需要在Windows 8計算機上工作。

我不知道您是否仍然對解決方案感興趣。 您必須使用CCD(連接和配置顯示器),並且只能通過使用dllimport調用Windows函數來實現。 這是CCD的鏈接https://msdn.microsoft.com/en-us/library/windows/hardware/ff539367(v=vs.85).aspx

為此,您必須撥打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_PATH_INFO和DisplayConfigModeInfo。 它們不能為null。 但是,這兩個結構還包含其他幾種類型,因此無法在此處粘貼。

如果您點擊以下鏈接,則會在github上找到一個示例項目。 機器人,自動旋轉@ Github上

從那里可以復制丟失的結構。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM