Detect the type of your monitor

UPDATE : Here is the monitor management application !

MonitorConfigurationAPI

Requirements : Vista and a display monitor with Vista drivers.

Usage : Click ‘Probe’ button then wait a few seconds !

Issues

  • Color temperature doesn’t produce expected results
  • During detection, some monitors may change their settings

If you don’t have a Vista-specific driver, you shouldn’t install an old XP driver otherwise it will break a couple of things on your system like monitor management for instance. You may think that you can roll-back to the previous driver, but it’ll be broken anyway ! I have seen some results with monitor that don’t have Vista drivers with the Generic PnP Monitor that is installed by default, though.


For my MAME GUI project,

I needed to detect what is the type of the monitor plugged onto the PC. This then, would allow me to provide custom scanlines PNGs, dependent of the technology used.

CRT ?

CRT

or LCD ?

LCD

Knowing that LCD does blurry stretching when not set at its native resolution, it is critical to know what display we are going to play on, in order to provide The (best possible) visual experience.

Proper arcade games emulation is somewhat sensitive to your display settings, hence, it’s always best to try provide nearest if not exact, display settings (resolution & refresh rate).

This all came out when I decided to try MAME, seriously (this time) on my LCD screen.
I got the following conclusion : it is possible to have a very good display experience even on LCDs, compared to using PowerStrip with my CRT.

While I have a great P1130 which is nothing more than a repainted G520 from Sony and is very good, if not one of the best CRTs to play your arcade games on, I like to play MAME quickly on my desktop PC (which in fact is a laptop) who is connected to the LCD screen. This is because since I got a new PC, the old Precision 360 workstation has been converted to a gaming-only PC. Too lazy to stand up and play just like in a real arcade game …

I thought : “This should be simple to get, I only need to know what is the type of screen, nothing more. (So it’s gonna be easy, yeah ?)”

But life was different,

In fact this post is kind of, the tip of the iceberg I’ve been sitting on and didn’t even know there was an iceberg under my feets until recently … So I decided to write this post, because now I got it working and other people can benefit from it.

I knew that display monitors have a protocol so the PC can speak with them, DDC/CI.

But here the problems comes,

  • The protocol is using nothing more than I²C
  • This is something low-level, not addressable with C# directly

And the list grows with time, why such simple request be so complicated to code ?

Now here are the possible solutions,

  • Get EDID string from Windows registry
    (Nice try but the string is in its raw form, decode it ? the specifications are not free …)
  • Use a software like softMCCS, or better, an SDK like WinI2C/DDC,
    (Nice try again but these analysis softwares are stand-alone application, and while WinI2C is exactly what is needed, it’s pricey and not to consider because of the target project : Another free MAME GUI (already claiming it’s the best).

While I’ve spent some time on WinI2C, the time-bombed samples always crashed for me, though the compiled demo ran … so I haven’t even been able to use it !

Now I don’t really need it because i have the same thing I coded myself but this wouldn’t happen without help right from Microsoft :-) considering you have Vista or better.

Monitor Configuration

You can use the monitor configuration functions to get information from a monitor and to change a monitor’s settings. You can use these functions to :

* Change a monitor’s geometry settings, such as the width and height of the display.
* Change image settings, such as brightness and contrast.
* Reset a monitor’s settings to their factory defaults.
* Degauss the monitor.

Internally, the monitor configuration functions use the Display Data Channel Command Interface (DDC/CI) to send commands to the monitor.
Now while this kicks ass, again, it’s for C++ …

Okay it does 99% of the job, all you have to do is call the functions you need, in fact it is even handier for my project as I am even able to change the colors of the monitor (if supported), great for monochrome emulation !

Now the only thing we need is a C# wrapper. (But some of it ran into trouble)

It got stuck when trying to get the physical monitors from the monitor, the pointer pointing to 0 was indeed correct (a pointer of pointer ?). While I hate pointers I find them working great when they are tamed.

But you still have to do a lot of things even with this API to get your Graal.

Monitor Detect API

In the next part I will unveil a complete monitor configuration wrapper for C# :-)

Monitor Detect Class Diagram
This is longer than expected as I decided to fully document it, and it’s tedious !
(I am already considering another project that creates P/Invoke declarations fully documented from MSDN site but here comes dirty HTML and Regular Expressions …)


Post a Comment

Your email is never shared. Required fields are marked *

*
*