Is it possible to get the screen pixel resolution in mm using Win32 APIs ? I have an application which is showing 0.3472222222222222 as the value for this on my 1280x1024 monitor with 96 dpi . But I am not able to find out how it got this value. Any clues will be helpful. I can use MFC also if required.
EDIT Sorry for the confusion, the software I am talking about was not using the current screen resolution. It was reading it from some config file.
Get device caps for the monitor gives you both size in pixels and mm thus:
HDC screen = GetDC(NULL);
int hSize=GetDeviceCaps(screen,HORZSIZE);
int hRes=GetDeviceCaps(screen,HORZRES);
float PixelsPerMM=(float)hRes/hSize; // pixels per millimeter
float PixelsPerInch=PixelsPerMM*25.4; //dpi
0.3472222222222222 mm per pixel is in fact equivalent to approximately 73 dpi. Windows uses two standard settings 72dpi and 96dpi, but custom values are also supported. These are nominal values and may not bear any relationship to the physical screen. For example it is possible to have a physically 96dpi screen set to 72dpi, and this will affect the scaling of images and layout in various applications as well as the size of system fonts and icons.
The default for Windows is 72dpi, and I have found that some applications (often in their "About" and dialog boxes) do not render correctly when set to other values. If your application reports 0.34, it seems likely that it is set to 72dpi or a custom value regardless of physical resolution. When set to match the physical resolution, the page width in say Word for example when set to a zoom level of 100% will match the physical paper size. Since this metric can be set by the end user, it is not directly related to the actual resolution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With