From fb35c93877dde060cbd58dd3c8dd5906ea64d659 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Fri, 24 Jan 2025 14:34:49 +0000 Subject: [PATCH] [Settings]Fix ZoomIt page changing current directory (#37052) --- .github/actions/spell-check/expect.txt | 1 + src/settings-ui/Settings.UI/Helpers/OpenFileName.cs | 6 ++++++ .../Settings.UI/SettingsXAML/Views/ZoomItPage.xaml.cs | 1 + 3 files changed, 8 insertions(+) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index 325b984c1c..9a0ba0dbe7 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -993,6 +993,7 @@ NNN NOACTIVATE NOAGGREGATION NOASYNC +NOCHANGEDIR NOCLIP NOCLOSEPROCESS NOCOALESCE diff --git a/src/settings-ui/Settings.UI/Helpers/OpenFileName.cs b/src/settings-ui/Settings.UI/Helpers/OpenFileName.cs index 3d7c1d8e90..2a48deecef 100644 --- a/src/settings-ui/Settings.UI/Helpers/OpenFileName.cs +++ b/src/settings-ui/Settings.UI/Helpers/OpenFileName.cs @@ -33,4 +33,10 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers public IntPtr Hook = IntPtr.Zero; public string Template; } + + // https://learn.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-openfilenamea + public enum OpenFileNameFlags + { + OFN_NOCHANGEDIR = 0x00000008, + } } diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/ZoomItPage.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Views/ZoomItPage.xaml.cs index ab90af4ed3..b0e5483533 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/ZoomItPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/ZoomItPage.xaml.cs @@ -35,6 +35,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views openFileName.Title = title; openFileName.FilterIndex = initialFilter; openFileName.DefExt = null; + openFileName.Flags = (int)OpenFileNameFlags.OFN_NOCHANGEDIR; // OFN_NOCHANGEDIR flag is needed, because otherwise GetOpenFileName overwrites the process working directory. IntPtr windowHandle = WinRT.Interop.WindowNative.GetWindowHandle(App.GetSettingsWindow()); openFileName.Hwnd = windowHandle;