如何在 C# 中启用第二个监视器? [英] How do I enable a second monitor in C#?

查看:28
本文介绍了如何在 C# 中启用第二个监视器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以以编程方式启用第二个监视器并在 C# 中将 Windows 桌面扩展到它上?它需要做相当于打开下图中的复选框.

Is it possible to enable a second monitor programatically and extend the Windows Desktop onto it in C#? It needs to do the equivalent of turning on the checkbox in the image below.

推荐答案

MSDN Device上下文函数

你基本上需要做的:

使用 EnumDisplayDevices() API 调用枚举显示设备系统并寻找那些没有DISPLAY_DEVICE_ATTACHED_TO_DESKTOP标志集(这将包括任何镜像设备,所以不是所有的物理显示器.)一旦你找到您需要获得的显示设备将其更改为有效的显示模式,你可以通过调用找到这个EnumDisplaySettingsEx() API 调用 -通常你会显示所有可用模式并允许用户选择但是在你的情况下听起来像这样可以硬编码并为您节省一个额外的步骤.为了为了保证您的未来申请虽然我建议有这很容易改变,而无需每次都挖掘源头,注册表项将是显而易见的选择.一旦你整理好了输出一个 DevMode 显示包含有关信息的结构显示定位(设置像素宽度/高度、位置、DisplayFrequency 和 BitsPerPel属性)然后在字段成员.最后打电话用这个改变DisplaySettingsEx()设置结构并确保发送重置和更新注册表标志.这应该就是你所需要的,希望这个有帮助,

Use the EnumDisplayDevices() API call to enumerate the display devices on the system and look for those that don't have the DISPLAY_DEVICE_ATTACHED_TO_DESKTOP flag set (this will include any mirroring devices so not all will be physical displays.) Once you've found the display device you'll need to get a valid display mode to change it to, you can find this by calling the EnumDisplaySettingsEx() API call - Generally you'd display all the available modes and allow the user to choose however in your case it sounds like this may be possible to hard-code and save you an additional step. For the sake of future-proofing your application though I'd suggest having this easily changeable without having to dig through the source every time, a registry key would be the obvious choice. Once you've got that sorted out populate a DevMode display structure with the information about the display positioning (set the PelsWidth/Height, Position, DisplayFrequency and BitsPerPel properties) then set these flags in the fields member. Finally call ChangeDisplaySettingsEx() with this settings structure and be sure to send the reset and update registry flags. That should be all you need, hope this helps,

DISPLAY_DEVICE 使用 PInvoke 导入结构

DISPLAY_DEVICE structure import using PInvoke

EnumDisplayDevices 函数导入

EnumDisplaySettingsEx 函数导入

等等.其余的功能可以通过简单的名称搜索找到.

etc. the rest of them functions can be found with a simple search by name.

这篇关于如何在 C# 中启用第二个监视器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆