如何禁用辅助监视器(使用ChangeDisplaySettingsEx)? [英] How to disable a secondary monitor (with ChangeDisplaySettingsEx)?

查看:52
本文介绍了如何禁用辅助监视器(使用ChangeDisplaySettingsEx)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按照此处提供了MSDN ,以禁用辅助监视器.

I'm trying to follow the instructions on MSDN given here to disable a secondary monitor.

我正在尝试专门使用这组功能以允许与Windows的较早版本兼容.

I'm trying to use specifically this set of functions to allow compatibility with older versions of Windows.

但是,我无法禁用监视器.我正在Windows 7 x64上运行和测试它.我所得到的只是一个闪烁的屏幕.该代码肯定能正确检测到显示器-我设法更改了分辨率并轻松查看了其显示模式.

However, I can't manage to disable a monitor. I'm running and testing this on Windows 7 x64. All I get is a flickering screen. The code definitely detects the monitor properly - I managed to change resolution and view it's display modes easily.

这是我的代码的(部分)-我在DEVMODE的字段上尝试了很多变体

Here are (parts) of my code - I tried a lot of variations on the fields for DEVMODE

DEVMODE    deleteScreenMode;
ZeroMemory(&deleteScreenMode, sizeof(DEVMODE));
deleteScreenMode.dmSize = sizeof(DEVMODE);
deleteScreenMode.dmDriverExtra = 0;
deleteScreenMode.dmFields = DM_POSITION | DM_PELSHEIGHT | DM_PELSWIDTH;
deleteScreenMode.dmPelsWidth = 0;
deleteScreenMode.dmPelsHeight = 0;

POINTL delete;
deleteion.x=0;
deleteion.y=0;
deleteScreenMode.dmPosition = deleteion;

LONG result = ChangeDisplaySettingsEx(devName, 
                                        &deleteScreenMode,
                                        NULL,
                                        CDS_UPDATEREGISTRY,
                                        NULL);

有人对此有经验吗?谢谢

Does anyone have experience with this? Thanks

推荐答案

我已经决定提出另一个问题-设置主显示-幸​​好我偶然发现了解决方案.禁用监视器的条件有2个,未在任何地方指定:1)您不能动态禁用监视器-您必须使用CDS_UPDATEREGISTRY将其写入注册表.2)更重要的是,出于某些奇怪的原因,您必须先将更改存储在注册表中(有或没有CDS_NORESET,都没有关系),然后然后再次使用带有NULL值的ChangeDisplaySettingsEx来使变化发生了.这可能需要将两个显示器都连接到同一显示设备上,我不确定...

I've decided to advance into a different problem - setting a primary display - and by pure luck I've stumbled into the solution. There are 2 conditions to disable a monitor that aren't specified anywhere: 1) You can't disable the monitor dynamically - you must use CDS_UPDATEREGISTRY to write it into the registry. 2) More importantly, for some weird reason, you must first store the change in the registry (with or without CDS_NORESET, it doesn't matter), and then use again ChangeDisplaySettingsEx with NULL values to make the changes happen. This might have something to do both monitors connected to the same display device, I'm not sure...

无论如何,以下是对我有用的代码:

Anyway here is the code that worked for me:

result = ChangeDisplaySettingsEx(devName, &deleteScreenMode,
                                        NULL,
                                         CDS_UPDATEREGISTRY | CDS_NORESET ,
                                        NULL);
ChangeDisplaySettingsEx (NULL, NULL, NULL, NULL, NULL);

希望有一天能对某人有所帮助.

Hope it'll help someone somewhere someday.

这篇关于如何禁用辅助监视器(使用ChangeDisplaySettingsEx)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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