Solved

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

Posted on 2004-10-26
342 Views
Last Modified: 2011-09-20
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
Question by:Trancos
    7 Comments
     
    LVL 55

    Accepted Solution

    by:
    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
     
    LVL 6

    Assisted Solution

    by:Svetlin_Panayotov
    For basic information about display depth/resolution etc. you can use EnumDisplayDevices and EnumDisplaySettings / EnumDisplaySettingsEx.
    0
     
    LVL 6

    Expert Comment

    by:Svetlin_Panayotov
    Whoops.Sorry jamie - bad refresh again :(
    0
     
    LVL 1

    Author Comment

    by:Trancos
    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
     
    LVL 55

    Expert Comment

    by:Jaime Olivares
    > 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
     
    LVL 1

    Author Comment

    by:Trancos
    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
     
    LVL 6

    Expert Comment

    by:Svetlin_Panayotov
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    This video Micro Tutorial is the second in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 (http://www.experts-exchange.com/articles/17490/). But the ability to create custom scanning profiles a…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now