C++查看显卡支持的分辨率

发布于 2024-09-30 07:54:51 字数 471 浏览 8 评论 0原文

我正在编写一个小程序,让我来回切换分辨率,因为我的投影仪无法处理与屏幕相同的分辨率。我已经知道如何使用 Windows API 设置屏幕分辨率。以及使用 Windows API 或 QT4 工具包读取当前分辨率。我的问题是我想要一个包含屏幕和显卡支持的所有不同分辨率的菜单。该程序将被分发,因此我需要该程序实际与显卡通信以找出它支持的内容。我想要使​​用的唯一 API 是 Windows API 或 QT4 工具包,但我不认为 QT4 会这样做,除非您以奇怪的方式使用图形小部件。

我非常确定使用 WINDOWS API 可以实现这一点。我只是不知道该怎么做。

哦,请放宽我的要求,我熟悉 QT4 和 C++,但我通常是一名 Linux 程序员,我是为别人写这篇文章的。我用 Windows API 做过的唯一一件事就是制作一个消息框、设置背景和使用系统变量。所以请简单解释一下这个过程。请不要只发布 msdn 的链接,我讨厌他们的文档,而且我讨厌 Microsoft。我一年可能使用两次窗户。

I am writing a small program to let me switch my resolution back and forth because my projector cannot handle the same resolution as my screen. I already know how to set the screen resolution using the windows API. As well as read the current resolution using the windows API or the QT4 toolkit. My problem is I want a menu of all of the different resolutions supported by the screen and graphics card. This program will be distributed so I need the program to actually communicate to the graphics card to find out what it supports. The only API I want to use is the windows API, or the QT4 toolkit, but I don't think QT4 does that unless you are using the graphics widgets in odd ways.

I am pretty sure this is possible with the WINDOWS API. I just don't know how to do it.

Oh and please cut me some slack, I am familiar with QT4 and C++ but I am typically a Linux programmer, I am writing this for someone else. The only thing I have ever done with the windows API is make a message box, set the background, and used system variables. So please explain the process simply. Please don't just post a link to the msdn, I hate their documentation, and I hate Microsoft. I use windows maybe twice a year.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鸵鸟症 2024-10-07 07:54:51

在一般情况下,以下内容可能适合您

DEVMODE dm = { 0 };
dm.dmSize = sizeof(dm);
for( int iModeNum = 0; EnumDisplaySettings( NULL, iModeNum, &dm ) != 0; iModeNum++ ) {
  cout << "Mode #" << iModeNum << " = " << dm.dmPelsWidth << "x" << dm.dmPelsHeight << endl;
  }

这应该打印出运行 .exe 的当前显示器上所有支持的分辨率。假设您没有使用多显示器显卡,这应该可以工作。否则,您必须在每个显示器上使用 EnumDisplayDevices 循环。

一旦确定了您想要的分辨率,您就可以使用“ChangeDisplaySettingsEx”将显示更改为您想要的模式。

使用 DirectX 是可能的,但我不推荐它,因为代码要复杂得多(必须初始化 DirectX 并使用 COM 指针),除非您计划实际使用 DirectX 不仅仅是确定显示分辨率。

The following should probably work for you in the general case

DEVMODE dm = { 0 };
dm.dmSize = sizeof(dm);
for( int iModeNum = 0; EnumDisplaySettings( NULL, iModeNum, &dm ) != 0; iModeNum++ ) {
  cout << "Mode #" << iModeNum << " = " << dm.dmPelsWidth << "x" << dm.dmPelsHeight << endl;
  }

This should print out all the supported resolutions on the current display that the .exe is running on. Assuming you're not dealing with a multi-display graphics card this should work. Otherwise you'd have to use EnumDisplayDevices loop over each display.

Once you figure out what resolution you want you can use 'ChangeDisplaySettingsEx' to change the display to the mode you want.

Using DirectX is possible but I wouldn't recommend it as the code is alot more complicated (having to initialize DirectX and using COM pointers) unless you plan to actually use DirectX for more than just determining display resolutions.

不疑不惑不回忆 2024-10-07 07:54:51

EnumDisplaySettings :)

来自 MSDN:

“获取当前显示设置,请将 iModeNum 参数中的 ENUM_CURRENT_SETTINGS 常量传递给 EnumDisplaySettings API,如以下 C++ 代码所示。”

DEVMODE dm;
// initialize the DEVMODE structure
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
{
// inspect the DEVMODE structure to obtain details
// about the display settings such as
//  - Orientation
//  - Width and Height
//  - Frequency
//  - etc.
}

EnumDisplaySettings :)

From MSDN:

"To obtain the current display settings, pass the ENUM_CURRENT_SETTINGS constant in the iModeNum parameter to the EnumDisplaySettings API, as illustrated by the following C++ code."

DEVMODE dm;
// initialize the DEVMODE structure
ZeroMemory(&dm, sizeof(dm));
dm.dmSize = sizeof(dm);
if (0 != EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dm))
{
// inspect the DEVMODE structure to obtain details
// about the display settings such as
//  - Orientation
//  - Width and Height
//  - Frequency
//  - etc.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文