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

@ -945,6 +945,30 @@ namespace OpenTK.Platform.Windows
#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
#region Input functions

View file

@ -27,6 +27,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
namespace OpenTK.Platform.Windows
@ -39,6 +40,17 @@ namespace OpenTK.Platform.Windows
readonly object SyncRoot = new object();
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
public virtual INativeWindow CreateNativeWindow(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)