The physical screen size obtained by GetDeviceCaps is not the actual physical screen size

On Windows 7 I am using the following code to get the physical width in mm of the screen. "HSize" is 482, which is much larger than the actual size, which is about 310 (measured with a ruler). Why is this?

HDC screen = GetDC(NULL);
int hSize=GetDeviceCaps(screen,HORZSIZE);

      

PS: I need a DPI value to display maps.

+3


source to share


1 answer


As you can see from the comments, GetDeviceCaps (HORSZIE / VERTSIZE) is notoriously imprecise. It has always been this way, and it probably always will be. There's nothing you can do about it there, so you just have to pretend that this API doesn't exist and isn't moving on. It will not help you find the actual monitor size. You would be better off just accepting the fixed default and letting the user manually adjust the dimensions manually.

Luckily, someone has already done some research there and figured out the best way to find the physical display size in Windows. In a blog titled Reading Monitor Physical Settings, or: Getting EDID, the Right Way Ofek describes how you can get more accurate dimensions from montior EDID using Windows SetupAPI. The scheme of the procedure is described as follows:

  • Call SetupDiGetClassDevsEx to get the HDEVINFO handle.
  • Use this HDEVINFO in the SetupDiEnumDeviceInfo call to populate the SP_DEVINFO_DATA structure.
  • Use HDEVICE and HDEVINFO in the SetupDiOpenDevRegKey call to finally get the HKEY to the desired registry key - the one that contains the EDID block.


The linked blog post contains sample code and information on other alternative methods he tried.

Please note that even the EDID will not always be accurate. While this is what the monitor itself says is its own dimensions, there is still plenty of room for error. It can be easy for a vendor to get sizing in EDID wrong and the monitor will still perform just fine, so there is little incentive to use these values ​​correctly.

+9


source







All Articles