Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows GDI: horizontal/vertical DPI

Tags:

c++

c

windows

gdi

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?

like image 672
Rob Avatar asked Nov 24 '08 15:11

Rob


2 Answers

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.

like image 139
Orihara Avatar answered Nov 03 '22 00:11

Orihara


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!
like image 36
John Dibling Avatar answered Nov 03 '22 01:11

John Dibling