7

When obtaining the DPI for the screen under Windows (by using ::GetDeviceCaps) will the horizontal value always be the same as the vertical? For example:

HDC dc = ::GetDC(NULL);
const int xDPI = ::GetDeviceCaps(dc, LOGPIXELSX);
const int yDPI - ::GetDeviceCaps(dc, LOGPIXELSY);
assert(xDPI == yDPI);
::ReleaseDC(NULL, dc);

Are these values ever different?

2
  • Not since the 320x200 display mode became obsolete. Commented Aug 23, 2011 at 18:38
  • Why assume anything? You already know how to query for both, so why not just query for each of them? You might as well future-proof your code, just in case something comes along that happens to be different! Commented Aug 23, 2011 at 19:25

4 Answers 4

7

It's possible for it to be different, but that generally only applies to printers. It can be safely assumed that the screen will always have identical horizontal and vertical DPIs.

1
  • Don't do that. We may have to again contend with non-square pixels.
    – Joshua
    Commented May 6, 2015 at 15:37
1

I have never seen them be different, but on this MSDN page I see a comment that suggests that they might be:

   int nHorz = dc.GetDeviceCaps(LOGPIXELSX);
   int nVert = dc.GetDeviceCaps(LOGPIXELSY);

   // almost always the same in both directions, but sometimes not!
0

I've never seen a case where they're different, but the fact that there are two separate calls for it strongly suggests that they might be sometimes.

0

Its easy for them to be different if the monitor is set up to use a screen resolution ratio that is not the same as the physical screen ratio, such as a 4:3 resolution like 1600x1200 on a 16:9 display.

1
  • 1
    Even if the physical screen is not displaying square pixels, it is not possible to configure Windows to reflect this fact. Commented Aug 23, 2011 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.