8

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

  1. Computer Only
  2. Duplicate
  3. Extend
  4. Projector Only

Do any API calls exist which allow one to switch between these display modes?

I want to programmatically switch between monitor and HDMI TV (and do a bunch of other things simultaneously, hence Windows+p not being useful), but I'm hitting a brick wall.

Mehran
  • 1,409
  • 2
  • 17
  • 27
Lee John Moore
  • 128
  • 1
  • 1
  • 7

3 Answers3

13

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);
dsfgsho
  • 2,731
  • 2
  • 22
  • 39
  • You Sir, are magnificent. Thank you so much for this solution. I had no idea that DisplaySwitch.exe even existed. – Lee John Moore May 28 '13 at 12:24
  • yeah this what i am looking for is there any way to do without using displayswitch.exe because i want to do it silently. in windows it will open the Project to a Connected screen and then it switches.. – Ravi Kanth Apr 04 '17 at 10:32
  • Wouldn't it be better (and more supported) to use the Win32 API functions instead of calling another program? What if the program goes away in a future version of Windows, or changes it's command-line syntax. – Charles Oppermann May 29 '19 at 20:27
3

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.

DuckMaestro
  • 15,232
  • 11
  • 67
  • 85
Greg
  • 1,181
  • 13
  • 13
2

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

Community
  • 1
  • 1
dsfgsho
  • 2,731
  • 2
  • 22
  • 39
  • Unfortunately it doesn't work. I've tried the sample code on Stackoverflow and imported the Codeproject project directly yesterday and compiled. It simply won't enable the second monitor (HDMI TV) even though the correct display has been identified. I can change the resolution and do all kinds of other display related things with those API calls, but disabling the primary monitor and enabling the secondary one (and vice versa) is simply out of the question. It's disappointing that Windows 7 implemented these very specific 'presentation modes' without providing direct access to them via the API – Lee John Moore May 28 '13 at 11:37