Skip to content

Commit

Permalink
Fix for WPF DPI issue on .net 3.1.19 (#13551)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimecbernardo committed Oct 1, 2021
1 parent 34e81fd commit b0d35f5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/modules/imageresizer/ui/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ static App()

protected override void OnStartup(StartupEventArgs e)
{
// Fix for .net 3.1.19 making Image Resizer not adapt to DPI changes.
NativeMethods.SetProcessDPIAware();
var batch = ResizeBatch.FromCommandLine(Console.In, e?.Args);

// TODO: Add command-line parameters that can be used in lieu of the input page (issue #14)
Expand Down
3 changes: 3 additions & 0 deletions src/modules/imageresizer/ui/Utilities/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ internal class NativeMethods
[DllImport("user32.dll")]
internal static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);

[DllImport("user32.dll", SetLastError = true)]
internal static extern bool SetProcessDPIAware();

[StructLayout(LayoutKind.Sequential)]
public struct INPUT
{
Expand Down
3 changes: 3 additions & 0 deletions src/modules/launcher/PowerLauncher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public static void Main()
private void OnStartup(object sender, StartupEventArgs e)
{
Log.Info("On Startup.", GetType());

// Fix for .net 3.1.19 making PowerToys Run not adapt to DPI changes.
PowerLauncher.Helper.NativeMethods.SetProcessDPIAware();
var bootTime = new System.Diagnostics.Stopwatch();
bootTime.Start();
Stopwatch.Normal("App.OnStartup - Startup cost", () =>
Expand Down
3 changes: 3 additions & 0 deletions src/modules/launcher/PowerLauncher/Helper/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ internal static class NativeMethods
[DllImport("user32.dll")]
internal static extern IntPtr SetForegroundWindow(IntPtr hWnd);

[DllImport("user32.dll", SetLastError = true)]
internal static extern bool SetProcessDPIAware();

[DllImport("user32.dll")]
internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

Expand Down

0 comments on commit b0d35f5

Please sign in to comment.