简体   繁体   English

以编程方式更改“演示文稿显示模式”

[英]Programmatically changing the “presentation display mode”

The presentation display modes are those you see when using the Windows + p shortcut: 演示文稿显示模式是您在使用Windows + p快捷方式时看到的模式

  1. Computer Only 仅限计算机
  2. Duplicate 重复
  3. Extend 延伸
  4. Projector Only 仅限投影仪

Do any API calls exist which allow one to switch between these display modes? 是否存在允许在这些显示模式之间切换的API调用?

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. 我想以编程方式在显示器和HDMI电视之间切换(并同时做一堆其他事情,因此Windows + p没有用),但我正在打砖墙。

In case the EnumDisplaySettingsEx and ChangeDisplaySettingsEx functions do not work for you, you can also use this: 如果EnumDisplaySettingsEx和ChangeDisplaySettingsEx函数不适合您,您还可以使用:

        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. 这将根据所需的配置调用DisplaySwitcher不同的参数。 You can thus call: 你可以这样称呼:

   SetDisplayMode(DisplayMode.Extend);

You can obtain and change the display setting using EnumDisplaySettingsEx and ChangeDisplaySettingsEx : 您可以使用EnumDisplaySettingsExChangeDisplaySettingsEx获取和更改显示设置:

The ChangeDisplaySettingsEx function changes the settings of the specified display device to the specified graphics mode. ChangeDisplaySettingsEx函数将指定显示设备的设置更改为指定的图形模式。

Check this Codeproject project and this Stackoverflow question for example code 检查此Codeproject项目和此Stackoverflow问题以获取示例代码

You can set the desktop display mode with SetDisplayConfig() eg. 您可以使用SetDisplayConfig()设置桌面显示模式,例如。

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

You can retrieve the current display mode with QueryDisplayConfig() . 您可以使用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 ++。 C# would require DLL imports. C#需要DLL导入。

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

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