How to set Display Settings to EXTEND mode in Windows 7 using C++?(如何使用 C++ 在 Windows 7 中将显示设置设置为 EXTEND 模式?)
问题描述
在我的 C++ Win32 程序中,我想将当前显示设置设置为扩展"模式.我用谷歌搜索,发现 SetDisplayConfig() 是在 Windows 7 中前进的方式(我在 Windows 7 上),但现在我有点卡住如何继续作为 MSDN 解释(链接 这里)非常令人困惑.我对 C++ 和 API 编程非常陌生,所以我很难理解这一点.
In my C++ Win32 program I want to set the current Display Settings to "Extend" mode. I Googled and found out that SetDisplayConfig() is the way to go forward in Windows 7 (I'm on Windows 7) but now I am kind of stuck how to proceed as the MSDN explanation (link here) is pretty confusing. I am very much new to C++ and API programming so I am finding it difficult to understand this.
我非常感谢一些代码示例和解释.提前致谢!
I would highly appreciate some code sample and an explanation. Thanks in advance!
推荐答案
好的,我想出了答案.
识别当前配置:
UINT32 PathArraySize = 0;
UINT32 ModeArraySize = 0;
DISPLAYCONFIG_PATH_INFO* PathArray;
DISPLAYCONFIG_MODE_INFO* ModeArray;
DISPLAYCONFIG_TOPOLOGY_ID CurrentTopology;
GetDisplayConfigBufferSizes(QDC_ALL_PATHS, &PathArraySize, &ModeArraySize);
PathArray = (DISPLAYCONFIG_PATH_INFO*)malloc(PathArraySize * sizeof(DISPLAYCONFIG_PATH_INFO));
memset(PathArray, 0, PathArraySize * sizeof(DISPLAYCONFIG_PATH_INFO));
ModeArray = (DISPLAYCONFIG_MODE_INFO*)malloc(ModeArraySize * sizeof(DISPLAYCONFIG_MODE_INFO));
memset(ModeArray, 0, ModeArraySize * sizeof(DISPLAYCONFIG_MODE_INFO));
LONG ret = QueryDisplayConfig(QDC_DATABASE_CURRENT,&PathArraySize, PathArray, &ModeArraySize, ModeArray, &CurrentTopology);
// Above CurrentTopology variable will aquire the current display setting (ie Extend, Duplicate etc)
free(PathArray);
free(ModeArray);
设置所需的显示设置(扩展、复制等):
To set the required display setting (Extend, Duplicate etc):
SetDisplayConfig(0,NULL,0,NULL,SDC_TOPOLOGY_EXTEND|SDC_APPLY);
或
SetDisplayConfig(0,NULL,0,NULL,SDC_TOPOLOGY_CLONE|SDC_APPLY);
这篇关于如何使用 C++ 在 Windows 7 中将显示设置设置为 EXTEND 模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 C++ 在 Windows 7 中将显示设置设置为 EXTEND 模式?


基础教程推荐
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01