Added support for high-dpi mode on Windows.

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
This commit is contained in:
thefiddler 2013-09-26 01:35:59 +02:00
parent c7e04c6097
commit 2e1bcaf280
2 changed files with 38 additions and 2 deletions

View file

@ -943,6 +943,30 @@ namespace OpenTK.Platform.Windows
[DllImport("user32.dll", SetLastError = true)]
public static extern HMONITOR MonitorFromWindow(HWND hwnd, MonitorFrom dwFlags);
#endregion
#region SetProcessDPIAware
/// <summary>
/// Sets the current process as dots per inch (dpi) aware.
/// Note: SetProcessDPIAware is subject to a possible race condition
/// if a DLL caches dpi settings during initialization.
/// For this reason, it is recommended that dpi-aware be set through
/// the application (.exe) manifest rather than by calling SetProcessDPIAware.
/// </summary>
/// <returns>
/// If the function succeeds, the return value is true.
/// Otherwise, the return value is false.
/// </returns>
/// <remarks>
/// DLLs should accept the dpi setting of the host process
/// rather than call SetProcessDPIAware themselves.
/// To be set properly, dpiAware should be specified as part
/// of the application (.exe) manifest.
/// </remarks>
[DllImport("user32.dll")]
internal static extern BOOL SetProcessDPIAware();
#endregion
#endregion

View file

@ -26,7 +26,8 @@
#endregion
using System;
using System.Collections.Generic;
using System.Collections.Generic;
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;
public WinFactory()
{
if (System.Environment.OSVersion.Version.Major >= 6)
{
// Enable high-dpi support
// Only available on Windows Vista and higher
bool result = Functions.SetProcessDPIAware();
Debug.Print("SetProcessDPIAware() returned {0}", result);
}
}
#region IPlatformFactory Members