how can I query for graphics hardware capabilities/state under a Win32 environment?

Hi experts,

I'm programming a small OpenGL application on a Win32 window. I would like to automatically detect the graphics card that is installed on the system where the application is running, as well as its features (i.e. current resolution, current bit depth, current refresh rate,dual monitors?, if yes, which one is the primary, its resolution, refresh rate, maximum resolution, maximum refresh rate,...). So, basically, how can I query for graphics hardware capabilities?

At the moment, what I have is an structure that can hold the default resolution, default bit depth, default refresh rate, the name of the graphics card, the name of the vendor (e.g. NVIDIA), and the model of the graphics card. I do this by accesing a registry key, however, I think this is an "unelegant" way of doing it. I was thinking, maybe I could use some DirectX commands, I've heard that it is easier for obtaining hardware features.

Any piece of advice will be welcome, and since this is not an easy question (I've done a thourough search on the web, and have found nothing so far =( _  if you provide me with a very good answer, I'll double the points.
LVL 1
TrancosAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jaime OlivaresSoftware ArchitectCommented:
There is not a unique method to retrieve all the information you want.

To enumerate all your monitors, use EnumDisplayMonitors() WinAPI function (http://msdn.microsoft.com/library/en-us/gdi/monitor_82yb.asp). It will require a callback function.

Every time the callback function is callled, you will receive a HMONITOR handle, use this handle to obtain monitor coordinates and devicename by using GetMonitorInfo (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/monitor_27e7.asp)

 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Svetlin_PanayotovCommented:
For basic information about display depth/resolution etc. you can use EnumDisplayDevices and EnumDisplaySettings / EnumDisplaySettingsEx.
0
Svetlin_PanayotovCommented:
Whoops.Sorry jamie - bad refresh again :(
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

TrancosAuthor Commented:
Thanks for your comments. I have tried your solution Svetlin but there is one major problem, I can't use the windows.h header file, so EnumDisplayDevices is not accessible. Is there anything similar to this function that works with stdafx? or about the EnumDisplayMonitors() winapi function, I don't quite well how dos the callback function "MonitorEnumProc" works? what am I suppose to put in there?

I'm increasing the points for this questions, as time is becoming a problem.

Cheers
0
Jaime OlivaresSoftware ArchitectCommented:
> I have tried your solution Svetlin but there is one major problem, I can't use the windows.h header file, so EnumDisplayDevices is not accessible

I am not sure what do you mean with that, but there is a trick to use those functions:

#include "stdafx.h"
// some other included headers here

// this macro is needed before calling multimonitor functions
#define COMPILE_MULTIMON_STUBS
#include "multimon.h"

-----

About how to use it:

// Somewhere into your application
HMONITOR monitor = NULL;
EnumDisplayMonitors(NULL, NULL, enumMonitors, (LPARAM)&monitor);

// Here is the callback function, it will be called as many times as monitor you have installed

BOOL CALLBACK enumMonitors(HMONITOR monitor, HDC dc, LPRECT rect, LPARAM param)
{
   static moncount = 0;
   MONITORINFOEX mi;

      mi.cbSize = sizeof(MONITORINFOEX);
      if (GetMonitorInfo(monitor, (LPMONITORINFO)&mi)) {
                        // Process some monitor information here and increment monitor counter
                        moncount++;
                }
      return TRUE;
}
0
TrancosAuthor Commented:
Thank you Jaime, I have tried your approach, but every time I try to compile the program the compiler displays:
 error C2065: 'HMONITOR' : undeclared identifier

I have included:
>#include "stdafx.h"
>// some other included headers here
>
>// this macro is needed before calling multimonitor functions
>#define COMPILE_MULTIMON_STUBS
>#include "multimon.h"

Nevertheless this doesn't help, I have moved the "multimon.h" file from its original folder on VC7/frameworkSDK to the program's folder, but this didn't help =(

By the way, what I meant on  my previous comment, is that since I'm using "stdafx.h", there are some precompiler headers that don't allow the solution to use the library <windows.h> on my program.

Any other suggestions will be very much appreciate it.
0
Svetlin_PanayotovCommented:
I don't think that there's something wrong with the solutions I and jaime_olivares gave.Since Trancos is unable to use <windows.h> in the app - this will not work of course.So in this case - our comments are of no use.But maybe the question should be just marked as PAQ (with points refunded if possible) - because in any other case EnumDisplayDevices() and EnumDisplayMonitors() should do the work.

Svetlin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.