Only call GetDpiForWindow if it's actually available

apparently this is limited to windows 10 1607+
This commit is contained in:
CasualPokePlayer 2024-09-23 03:07:37 -07:00
parent 3ea0a5a2dd
commit 96b4de92af
2 changed files with 25 additions and 9 deletions

View File

@ -11,6 +11,29 @@ namespace BizHawk.Client.EmuHawk
{
public class DisplayManager : DisplayManagerBase
{
// this function requires at least windows 10
private static readonly unsafe delegate* unmanaged[Stdcall]<IntPtr, int> _getDpiForWindow;
static DisplayManager()
{
if (OSTailoredCode.IsUnixHost)
{
return;
}
var lib = OSTailoredCode.LinkedLibManager.LoadOrZero("user32.dll");
if (lib == IntPtr.Zero)
{
return;
}
unsafe
{
_getDpiForWindow = (delegate* unmanaged[Stdcall]<IntPtr, int>)
OSTailoredCode.LinkedLibManager.GetProcAddrOrZero(lib, "GetDpiForWindow");
}
}
private readonly Func<bool> _getIsSecondaryThrottlingDisabled;
private bool? _lastVsyncSetting;
@ -51,12 +74,8 @@ namespace BizHawk.Client.EmuHawk
public override Size GetPanelNativeSize() => _presentationPanel.NativeSize;
protected override int GetGraphicsControlDpi()
{
return OSTailoredCode.IsUnixHost
? DEFAULT_DPI
: Win32Imports.GetDpiForWindow(_graphicsControl.Handle);
}
protected override unsafe int GetGraphicsControlDpi()
=> _getDpiForWindow == null ? DEFAULT_DPI : _getDpiForWindow(_graphicsControl.Handle);
protected override Point GraphicsControlPointToClient(Point p) => _graphicsControl.PointToClient(p);

View File

@ -67,8 +67,5 @@ namespace BizHawk.Common
[DllImport("user32.dll", ExactSpelling = true)]
public static extern int TrackPopupMenuEx(IntPtr hmenu, TPM fuFlags, int x, int y, IntPtr hwnd, IntPtr lptpm);
[DllImport("user32.dll", ExactSpelling = true)]
public static extern int GetDpiForWindow(IntPtr hwnd);
}
}