Programmatically changing the “presentation display mode”

后端 未结 3 1812
不知归路
不知归路 2020-12-09 00:22

The presentation display modes are those you see when using the Windows+p shortcut:

  1. Computer Only
  2. Duplicate
相关标签:
3条回答
  • 2020-12-09 00:43

    You can set the desktop display mode with SetDisplayConfig() eg.

    SetDisplayConfig(0, NULL, 0, NULL, SDC_TOPOLOGY_EXTERNAL | SDC_APPLY);
    

    You can retrieve the current display mode with QueryDisplayConfig(). eg.

    DISPLAYCONFIG_TOPOLOGY_ID currentTopology;
    QueryDisplayConfig(QDC_DATABASE_CURRENT, &PathArraySize, PathArray, &ModeArraySize, ModeArray, &currentTopology);
    

    (Related source for this call here)

    This is for C++. C# would require DLL imports.

    0 讨论(0)
  • 2020-12-09 00:56

    In case the EnumDisplaySettingsEx and ChangeDisplaySettingsEx functions do not work for you, you can also use this:

            private void SetDisplayMode(DisplayMode mode)
            {
                var proc = new Process();
                proc.StartInfo.FileName = "DisplaySwitch.exe";
                switch (mode)
                {
                    case DisplayMode.External:
                        proc.StartInfo.Arguments = "/external";
                        break;
                    case DisplayMode.Internal:
                        proc.StartInfo.Arguments = "/internal";
                        break;
                    case DisplayMode.Extend:
                        proc.StartInfo.Arguments = "/extend";
                        break;
                    case DisplayMode.Duplicate:
                        proc.StartInfo.Arguments = "/clone";
                        break;
                }
                proc.Start();
            }
            enum DisplayMode
            {
                Internal,
                External,
                Extend,
                Duplicate
            }
    

    This will call the DisplaySwitcher with different arguments based on the required configuration. You can thus call:

       SetDisplayMode(DisplayMode.Extend);
    
    0 讨论(0)
  • 2020-12-09 01:02

    You can obtain and change the display setting using EnumDisplaySettingsEx and ChangeDisplaySettingsEx:

    The ChangeDisplaySettingsEx function changes the settings of the specified display device to the specified graphics mode.

    Check this Codeproject project and this Stackoverflow question for example code

    0 讨论(0)
提交回复
热议问题