Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Finding out what resolutions are supported by the graphics card

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.

like image 803
The Dude Avatar asked Nov 03 '10 16:11

The Dude


People also ask

How do I find my graphics card resolution?

Step 1: Right click on Windows desktop and select Screen resolution. Step 2: Click Advanced settings link. Step 3: Your graphics card properties dialog opens, then select the Adapter tab. Under the Adapter tab, you can view the specific type and other information of your graphics card.

How do I know my graphics card max support resolution?

Just search google for your card and check for the spec, look for the supported resolution part. Your card can only display maximum resolution as stated. If the monitor has higher resolution, it can be used with max resolution your card can display.

What is graphics card resolution?

Many mainstream cards are sufficient for gaming at 1080p resolutions at between 30-60 fps, but you'll need a high-end card for resolutions at or near 4K resolution with high in-game settings on the most demanding titles. So be sure to pair your GPU with the best gaming monitor for your needs.


2 Answers

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.

like image 105
MerickOWA Avatar answered Sep 21 '22 11:09

MerickOWA


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.
}
like image 36
YWE Avatar answered Sep 22 '22 11:09

YWE