Added support for high-dpi mode on Windows.
authorthefiddler <stapostol@gmail.com>
Wed, 25 Sep 2013 23:35:59 +0000 (01:35 +0200)
committerthefiddler <stapostol@gmail.com>
Wed, 25 Sep 2013 23:35:59 +0000 (01:35 +0200)
The platform factory for windows now calls SetProcessDPIAware
in order to enable support for high-dpi modes. The relevant
DllImport has been added to API.cs

Source/OpenTK/Platform/Windows/API.cs
Source/OpenTK/Platform/Windows/WinFactory.cs

index ccd77bc5478ee864afaeacf0e25f80cedf7ca000..87f2695feb267d2859383e102c0d7d24c1052af9 100644 (file)
@@ -943,6 +943,30 @@ namespace OpenTK.Platform.Windows
         [DllImport("user32.dll", SetLastError = true)]
         public static extern HMONITOR MonitorFromWindow(HWND hwnd, MonitorFrom dwFlags);
 
+        #endregion\r
+\r
+        #region SetProcessDPIAware\r
+\r
+        /// <summary>\r
+        /// Sets the current process as dots per inch (dpi) aware.\r
+        /// Note: SetProcessDPIAware is subject to a possible race condition\r
+        /// if a DLL caches dpi settings during initialization.\r
+        /// For this reason, it is recommended that dpi-aware be set through\r
+        /// the application (.exe) manifest rather than by calling SetProcessDPIAware.\r
+        /// </summary>\r
+        /// <returns>\r
+        /// If the function succeeds, the return value is true.\r
+        /// Otherwise, the return value is false.\r
+        /// </returns>\r
+        /// <remarks>\r
+        /// DLLs should accept the dpi setting of the host process\r
+        /// rather than call SetProcessDPIAware themselves.\r
+        /// To be set properly, dpiAware should be specified as part\r
+        /// of the application (.exe) manifest.\r
+        /// </remarks>\r
+        [DllImport("user32.dll")]\r
+        internal static extern BOOL SetProcessDPIAware();\r
+\r
         #endregion
 
         #endregion
index c5d8fcc34936c813d8f11aeffc7a91e78d22efba..877d63f30f94f253787df7dae320ee8148b3e501 100644 (file)
@@ -26,7 +26,8 @@
 #endregion
 
 using System;
-using System.Collections.Generic;
+using System.Collections.Generic;\r
+using System.Diagnostics;
 using System.Text;
 
 namespace OpenTK.Platform.Windows
@@ -37,7 +38,18 @@ namespace OpenTK.Platform.Windows
     class WinFactory : IPlatformFactory 
     {
         readonly object SyncRoot = new object();
-        IInputDriver2 inputDriver;
+        IInputDriver2 inputDriver;\r
+\r
+        public WinFactory()\r
+        {\r
+            if (System.Environment.OSVersion.Version.Major >= 6)\r
+            {\r
+                // Enable high-dpi support\r
+                // Only available on Windows Vista and higher\r
+                bool result = Functions.SetProcessDPIAware();\r
+                Debug.Print("SetProcessDPIAware() returned {0}", result);\r
+            }\r
+        }
 
         #region IPlatformFactory Members