Skip to content

Instantly share code, notes, and snippets.

@kahrl
Created January 17, 2015 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kahrl/ae1213d791014d4afffb to your computer and use it in GitHub Desktop.
Save kahrl/ae1213d791014d4afffb to your computer and use it in GitHub Desktop.
diff --git a/src/porting.cpp b/src/porting.cpp
index 885b36e..286b4e1 100644
--- a/src/porting.cpp
+++ b/src/porting.cpp
@@ -602,7 +602,16 @@ float getDisplayDensity()
/* return manually specified dpi */
return g_settings->getFloat("screen_dpi")/96.0;
}
-
+#elif defined(_WIN32)
+float getDisplayDensity()
+{
+ SetProcessDPIAware();
+ HDC screen = GetDC(NULL);
+ float dpi_x = GetDeviceCaps(screen, LOGPIXELSX);
+ float dpi_y = GetDeviceCaps(screen, LOGPIXELSY);
+ ReleaseDC(NULL, screen);
+ return (dpi_x + dpi_y) * 0.5;
+}
#else
float getDisplayDensity()
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment