title: Getting actual screen dpi/ppi under windows
body: <p>I would like to get the <strong>actual</strong> screen dpi/ppi, not the dpi setting used for font in C++.</p>
  
  <p>I tried with the following codes:</p>
  
  <p>Version 1, reports 72 dpi, which is wrong.</p>
  
  <pre><code>SetProcessDPIAware(); //true
  HDC screen = GetDC(NULL);
  double hSize = GetDeviceCaps(screen, HORZSIZE);
  double vSize = GetDeviceCaps(screen, VERTSIZE);
  double hRes = GetDeviceCaps(screen, HORZRES);
  double vRes = GetDeviceCaps(screen, VERTRES);
  double hPixelsPerInch = hRes / hSize * 25.4;
  double vPixelsPerInch = vRes / vSize * 25.4;
  ReleaseDC(NULL, screen);
  return (hPixelsPerInch + vPixelsPerInch) * 0.5;
  </code></pre>
  
  <p>Version 2, reports 96 dpi, which is the Windows dpi setting for font, but not the actual screen dpi.</p>
  
  <pre><code>SetProcessDPIAware(); //true
  HDC screen = GetDC(NULL);
  double hPixelsPerInch = GetDeviceCaps(screen,LOGPIXELSX);
  double vPixelsPerInch = GetDeviceCaps(screen,LOGPIXELSY);
  ReleaseDC(NULL, screen);
  return (hPixelsPerInch + vPixelsPerInch) * 0.5;
  </code></pre>