• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

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.
0
Trancos
Asked:
Trancos
  • 3
  • 2
  • 2
2 Solutions
 
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
 
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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now