Skip to content

Commit

Permalink
Stop calling GetDpiForWindow because it isn't supported until Windows…
Browse files Browse the repository at this point in the history
… 10.0.14393 or on Windows Server
  • Loading branch information
jnm2 committed Feb 25, 2021
1 parent 63949a3 commit 7375595
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,6 @@ dotnet_diagnostic.IDE0059.severity = warning

# CA1031: Do not catch general exception types
dotnet_diagnostic.CA1031.severity = warning

# CA1416: Validate platform compatibility
dotnet_diagnostic.CA1416.severity = warning;
5 changes: 1 addition & 4 deletions src/Techsola.InstantReplay/InstantReplayCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,7 @@ private static void AddFrames(object? state)
throw new Win32Exception(lastError);
}

var dpi = User32.GetDpiForWindow(window);
if (dpi == 0) return null; // This is what happens when the window handle becomes invalid.

return new(clientTopLeft.x, clientTopLeft.y, clientRect.right, clientRect.bottom, dpi);
return new(clientTopLeft.x, clientTopLeft.y, clientRect.right, clientRect.bottom);
}

#if !NET35
Expand Down
7 changes: 0 additions & 7 deletions src/Techsola.InstantReplay/Native/User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ public static WindowDeviceContextSafeHandle GetDC(IntPtr hWnd)
[DllImport("user32.dll", EntryPoint = "GetDC")]
private static extern IntPtr GetDC_PInvoke(IntPtr hWnd);

/// <summary>
/// <seealso href="https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdpiforwindow"/>
/// </summary>
[DllImport("user32.dll")]
[SupportedOSPlatform("windows10.0.14393")]
public static extern uint GetDpiForWindow(IntPtr hwnd);

/// <summary>
/// <seealso href="https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-geticoninfo"/>
/// </summary>
Expand Down
4 changes: 1 addition & 3 deletions src/Techsola.InstantReplay/WindowMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ private readonly struct WindowMetrics
public readonly int ClientTop;
public readonly int ClientWidth;
public readonly int ClientHeight;
public readonly uint Dpi;

public WindowMetrics(int clientLeft, int clientTop, int clientWidth, int clientHeight, uint dpi)
public WindowMetrics(int clientLeft, int clientTop, int clientWidth, int clientHeight)
{
ClientLeft = clientLeft;
ClientTop = clientTop;
ClientWidth = clientWidth;
ClientHeight = clientHeight;
Dpi = dpi;
}
}
}
Expand Down

0 comments on commit 7375595

Please sign in to comment.