From 9a8eabd5ee94366f3a90645bd45aa839f067afef Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 22:56:19 +0000 Subject: [PATCH 1/9] Bump Microsoft.Data.Sqlite from 9.0.0 to 9.0.1 Bumps [Microsoft.Data.Sqlite](https://github.com/dotnet/efcore) from 9.0.0 to 9.0.1. - [Release notes](https://github.com/dotnet/efcore/releases) - [Commits](https://github.com/dotnet/efcore/compare/v9.0.0...v9.0.1) --- updated-dependencies: - dependency-name: Microsoft.Data.Sqlite dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Flow.Launcher.Plugin.BrowserBookmark.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj index 03ac0491f..d7a626e1d 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Flow.Launcher.Plugin.BrowserBookmark.csproj @@ -95,7 +95,7 @@ - + From 208e4a8c204749ac9c78ab32ed0172c7c1075b77 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 22:56:59 +0000 Subject: [PATCH 2/9] Bump VirtualizingWrapPanel from 2.1.0 to 2.1.1 Bumps [VirtualizingWrapPanel](https://github.com/sbaeumlisberger/VirtualizingWrapPanel) from 2.1.0 to 2.1.1. - [Release notes](https://github.com/sbaeumlisberger/VirtualizingWrapPanel/releases) - [Commits](https://github.com/sbaeumlisberger/VirtualizingWrapPanel/compare/v2.1.0...v2.1.1) --- updated-dependencies: - dependency-name: VirtualizingWrapPanel dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Flow.Launcher/Flow.Launcher.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/Flow.Launcher.csproj b/Flow.Launcher/Flow.Launcher.csproj index 788beddfb..16228258f 100644 --- a/Flow.Launcher/Flow.Launcher.csproj +++ b/Flow.Launcher/Flow.Launcher.csproj @@ -100,7 +100,7 @@ - + From 69bf7c6b63ff3988e583508583e7543ed1956b2e Mon Sep 17 00:00:00 2001 From: cibere <71997063+cibere@users.noreply.github.com> Date: Thu, 6 Feb 2025 18:34:44 -0800 Subject: [PATCH 3/9] add BackToQueryResults to JsonRPCPublicAPI --- .../Plugin/JsonRPCV2Models/JsonRPCPublicAPI.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Flow.Launcher.Core/Plugin/JsonRPCV2Models/JsonRPCPublicAPI.cs b/Flow.Launcher.Core/Plugin/JsonRPCV2Models/JsonRPCPublicAPI.cs index b8bfee591..2d49e4840 100644 --- a/Flow.Launcher.Core/Plugin/JsonRPCV2Models/JsonRPCPublicAPI.cs +++ b/Flow.Launcher.Core/Plugin/JsonRPCV2Models/JsonRPCPublicAPI.cs @@ -173,5 +173,10 @@ namespace Flow.Launcher.Core.Plugin.JsonRPCV2Models { _api.OpenAppUri(appUri); } + + public void BackToQueryResults() + { + _api.BackToQueryResults(); + } } } From a3cc5e25f9e8cad6cde6a7360a10da2400589f10 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 7 Feb 2025 16:05:35 +0800 Subject: [PATCH 4/9] Fix unix directory seperator issue --- Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs | 2 ++ .../Search/DirectoryInfo/DirectoryInfoSearch.cs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs index e7b43c555..bc1fb8e7a 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs @@ -31,6 +31,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search internal const string DefaultContentSearchActionKeyword = "doc:"; + internal const char UnixDirectorySeparator = '/'; + internal const char DirectorySeparator = '\\'; internal const string WindowsIndexingOptions = "srchadmin.dll"; diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs index 9fd495f49..e3e1c62e6 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs @@ -1,4 +1,4 @@ -using Flow.Launcher.Infrastructure.Logger; +using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Plugin.SharedCommands; using System; using System.Collections.Generic; @@ -12,6 +12,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo { internal static IEnumerable TopLevelDirectorySearch(Query query, string search, CancellationToken token) { + // if user uses the unix directory separator, we need to convert it to windows directory separator + search = search.Replace(Constants.UnixDirectorySeparator, Constants.DirectorySeparator); + var criteria = ConstructSearchCriteria(search); if (search.LastIndexOf(Constants.AllFilesFolderSearchWildcard) > From 3ee3528e5433c6da1f6f1c37095e92c8ec9153ba Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 7 Feb 2025 16:40:45 +0800 Subject: [PATCH 5/9] Revert "Fix unix directory seperator issue" This reverts commit a3cc5e25f9e8cad6cde6a7360a10da2400589f10. --- Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs | 2 -- .../Search/DirectoryInfo/DirectoryInfoSearch.cs | 5 +---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs index bc1fb8e7a..e7b43c555 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs @@ -31,8 +31,6 @@ namespace Flow.Launcher.Plugin.Explorer.Search internal const string DefaultContentSearchActionKeyword = "doc:"; - internal const char UnixDirectorySeparator = '/'; - internal const char DirectorySeparator = '\\'; internal const string WindowsIndexingOptions = "srchadmin.dll"; diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs index e3e1c62e6..9fd495f49 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/DirectoryInfo/DirectoryInfoSearch.cs @@ -1,4 +1,4 @@ -using Flow.Launcher.Infrastructure.Logger; +using Flow.Launcher.Infrastructure.Logger; using Flow.Launcher.Plugin.SharedCommands; using System; using System.Collections.Generic; @@ -12,9 +12,6 @@ namespace Flow.Launcher.Plugin.Explorer.Search.DirectoryInfo { internal static IEnumerable TopLevelDirectorySearch(Query query, string search, CancellationToken token) { - // if user uses the unix directory separator, we need to convert it to windows directory separator - search = search.Replace(Constants.UnixDirectorySeparator, Constants.DirectorySeparator); - var criteria = ConstructSearchCriteria(search); if (search.LastIndexOf(Constants.AllFilesFolderSearchWildcard) > From 5ee110b3b741b310bfebffc4edbf5b371c0f5db4 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 7 Feb 2025 16:42:01 +0800 Subject: [PATCH 6/9] Fix unix directory seperator issue --- Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs | 3 ++- Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs index e7b43c555..4bddfd9b2 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/Constants.cs @@ -22,7 +22,6 @@ namespace Flow.Launcher.Plugin.Explorer.Search internal const string WindowsIndexErrorImagePath = "Images\\index_error2.png"; internal const string GeneralSearchErrorImagePath = "Images\\robot_error.png"; - internal const string ToolTipOpenDirectory = "Ctrl + Enter to open the directory"; internal const string ToolTipOpenContainingFolder = "Ctrl + Enter to open the containing folder"; @@ -31,6 +30,8 @@ namespace Flow.Launcher.Plugin.Explorer.Search internal const string DefaultContentSearchActionKeyword = "doc:"; + internal const char UnixDirectorySeparator = '/'; + internal const char DirectorySeparator = '\\'; internal const string WindowsIndexingOptions = "srchadmin.dll"; diff --git a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs index 8fd167476..12df6c145 100644 --- a/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs +++ b/Plugins/Flow.Launcher.Plugin.Explorer/Search/SearchManager.cs @@ -187,6 +187,9 @@ namespace Flow.Launcher.Plugin.Explorer.Search var needToExpand = EnvironmentVariables.HasEnvironmentVar(querySearch); var path = needToExpand ? Environment.ExpandEnvironmentVariables(querySearch) : querySearch; + // if user uses the unix directory separator, we need to convert it to windows directory separator + path = path.Replace(Constants.UnixDirectorySeparator, Constants.DirectorySeparator); + // Check that actual location exists, otherwise directory search will throw directory not found exception if (!FilesFolders.ReturnPreviousDirectoryIfIncompleteString(path).LocationExists()) return results.ToList(); From 5313229fb918b19e99eddfd5023c41fed9724e66 Mon Sep 17 00:00:00 2001 From: zggsong Date: Fri, 14 Feb 2025 13:22:27 +0800 Subject: [PATCH 7/9] perf: hide main window from alt tab program switcher #2356 --- Flow.Launcher/Helper/WindowsInteropHelper.cs | 75 ++++++++++++++++++++ Flow.Launcher/MainWindow.xaml | 1 + Flow.Launcher/MainWindow.xaml.cs | 5 ++ 3 files changed, 81 insertions(+) diff --git a/Flow.Launcher/Helper/WindowsInteropHelper.cs b/Flow.Launcher/Helper/WindowsInteropHelper.cs index caf3f0a7f..eeb24af2e 100644 --- a/Flow.Launcher/Helper/WindowsInteropHelper.cs +++ b/Flow.Launcher/Helper/WindowsInteropHelper.cs @@ -148,4 +148,79 @@ public class WindowsInteropHelper return new Point((int)(matrix.M11 * unitX), (int)(matrix.M22 * unitY)); } + + #region Alt Tab + + private const int GWL_EXSTYLE = -20; + private const int WS_EX_TOOLWINDOW = 0x00000080; + private const int WS_EX_APPWINDOW = 0x00040000; + + [DllImport("user32.dll")] + private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex); + + [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)] + private static extern IntPtr IntSetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong); + + [DllImport("user32.dll", EntryPoint = "SetWindowLong", SetLastError = true)] + private static extern int IntSetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); + + [DllImport("kernel32.dll", EntryPoint = "SetLastError")] + private static extern void SetLastError(int dwErrorCode); + + private static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong) + { + SetLastError(0); // Clear any existing error + + if (IntPtr.Size == 4) return new IntPtr(IntSetWindowLong(hWnd, nIndex, IntPtrToInt32(dwNewLong))); + + return IntSetWindowLongPtr(hWnd, nIndex, dwNewLong); + } + + private static int IntPtrToInt32(IntPtr intPtr) + { + return unchecked((int)intPtr.ToInt64()); + } + + /// + /// Hide windows in the Alt+Tab window list + /// + /// To hide a window + public static void HideFromAltTab(Window window) + { + var helper = new WindowInteropHelper(window); + var exStyle = GetWindowLong(helper.Handle, GWL_EXSTYLE).ToInt32(); + + // Add TOOLWINDOW style, remove APPWINDOW style + exStyle = (exStyle | WS_EX_TOOLWINDOW) & ~WS_EX_APPWINDOW; + + SetWindowLong(helper.Handle, GWL_EXSTYLE, new IntPtr(exStyle)); + } + + /// + /// Restore window display in the Alt+Tab window list. + /// + /// To restore the displayed window + public static void ShowInAltTab(Window window) + { + var helper = new WindowInteropHelper(window); + var exStyle = GetWindowLong(helper.Handle, GWL_EXSTYLE).ToInt32(); + + // Remove the TOOLWINDOW style and add the APPWINDOW style. + exStyle = (exStyle & ~WS_EX_TOOLWINDOW) | WS_EX_APPWINDOW; + + SetWindowLong(helper.Handle, GWL_EXSTYLE, new IntPtr(exStyle)); + } + + /// + /// To obtain the current overridden style of a window. + /// + /// To obtain the style dialog window + /// current extension style value + public static int GetCurrentWindowStyle(Window window) + { + var helper = new WindowInteropHelper(window); + return GetWindowLong(helper.Handle, GWL_EXSTYLE).ToInt32(); + } + + #endregion } diff --git a/Flow.Launcher/MainWindow.xaml b/Flow.Launcher/MainWindow.xaml index f5fd729d4..da9e1a5b5 100644 --- a/Flow.Launcher/MainWindow.xaml +++ b/Flow.Launcher/MainWindow.xaml @@ -20,6 +20,7 @@ Closing="OnClosing" Deactivated="OnDeactivated" Icon="Images/app.png" + SourceInitialized="OnSourceInitialized" Initialized="OnInitialized" Left="{Binding Settings.WindowLeft, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Loaded="OnLoaded" diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index 8ca153afc..41dc68fd9 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -171,6 +171,11 @@ namespace Flow.Launcher Environment.Exit(0); } + private void OnSourceInitialized(object sender, EventArgs e) + { + WindowsInteropHelper.HideFromAltTab(this); + } + private void OnInitialized(object sender, EventArgs e) { } From 829dbaafe7fae537d487f4b67cfe593c01ac5081 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 14 Feb 2025 16:12:15 +0800 Subject: [PATCH 8/9] Use CSWin32 for code quality --- Flow.Launcher/Helper/WindowsInteropHelper.cs | 44 ++++++-------------- Flow.Launcher/NativeMethods.txt | 5 ++- 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/Flow.Launcher/Helper/WindowsInteropHelper.cs b/Flow.Launcher/Helper/WindowsInteropHelper.cs index eeb24af2e..4891bf41a 100644 --- a/Flow.Launcher/Helper/WindowsInteropHelper.cs +++ b/Flow.Launcher/Helper/WindowsInteropHelper.cs @@ -151,29 +151,11 @@ public class WindowsInteropHelper #region Alt Tab - private const int GWL_EXSTYLE = -20; - private const int WS_EX_TOOLWINDOW = 0x00000080; - private const int WS_EX_APPWINDOW = 0x00040000; - - [DllImport("user32.dll")] - private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex); - - [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)] - private static extern IntPtr IntSetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong); - - [DllImport("user32.dll", EntryPoint = "SetWindowLong", SetLastError = true)] - private static extern int IntSetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); - - [DllImport("kernel32.dll", EntryPoint = "SetLastError")] - private static extern void SetLastError(int dwErrorCode); - - private static IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong) + private static IntPtr SetWindowLong(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex, int dwNewLong) { - SetLastError(0); // Clear any existing error + PInvoke.SetLastError(WIN32_ERROR.NO_ERROR); // Clear any existing error - if (IntPtr.Size == 4) return new IntPtr(IntSetWindowLong(hWnd, nIndex, IntPtrToInt32(dwNewLong))); - - return IntSetWindowLongPtr(hWnd, nIndex, dwNewLong); + return PInvoke.SetWindowLong(hWnd, nIndex, dwNewLong); } private static int IntPtrToInt32(IntPtr intPtr) @@ -182,44 +164,44 @@ public class WindowsInteropHelper } /// - /// Hide windows in the Alt+Tab window list + /// Hide windows in the Alt+Tab window list /// /// To hide a window public static void HideFromAltTab(Window window) { var helper = new WindowInteropHelper(window); - var exStyle = GetWindowLong(helper.Handle, GWL_EXSTYLE).ToInt32(); + var exStyle = PInvoke.GetWindowLong(new(helper.Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE); // Add TOOLWINDOW style, remove APPWINDOW style - exStyle = (exStyle | WS_EX_TOOLWINDOW) & ~WS_EX_APPWINDOW; + var newExStyle = ((uint)exStyle | (uint)WINDOW_EX_STYLE.WS_EX_TOOLWINDOW) & ~(uint)WINDOW_EX_STYLE.WS_EX_APPWINDOW; - SetWindowLong(helper.Handle, GWL_EXSTYLE, new IntPtr(exStyle)); + SetWindowLong(new(helper.Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, (int)newExStyle); } /// - /// Restore window display in the Alt+Tab window list. + /// Restore window display in the Alt+Tab window list. /// /// To restore the displayed window public static void ShowInAltTab(Window window) { var helper = new WindowInteropHelper(window); - var exStyle = GetWindowLong(helper.Handle, GWL_EXSTYLE).ToInt32(); + var exStyle = PInvoke.GetWindowLong(new(helper.Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE); // Remove the TOOLWINDOW style and add the APPWINDOW style. - exStyle = (exStyle & ~WS_EX_TOOLWINDOW) | WS_EX_APPWINDOW; + var newExStyle = ((uint)exStyle & ~(uint)WINDOW_EX_STYLE.WS_EX_TOOLWINDOW) | (uint)WINDOW_EX_STYLE.WS_EX_APPWINDOW; - SetWindowLong(helper.Handle, GWL_EXSTYLE, new IntPtr(exStyle)); + SetWindowLong(new(helper.Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, (int)newExStyle); } /// - /// To obtain the current overridden style of a window. + /// To obtain the current overridden style of a window. /// /// To obtain the style dialog window /// current extension style value public static int GetCurrentWindowStyle(Window window) { var helper = new WindowInteropHelper(window); - return GetWindowLong(helper.Handle, GWL_EXSTYLE).ToInt32(); + return PInvoke.GetWindowLong(new(helper.Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE); } #endregion diff --git a/Flow.Launcher/NativeMethods.txt b/Flow.Launcher/NativeMethods.txt index 2b147c05f..88eeeca6e 100644 --- a/Flow.Launcher/NativeMethods.txt +++ b/Flow.Launcher/NativeMethods.txt @@ -14,4 +14,7 @@ FindWindowEx WINDOW_STYLE WM_ENTERSIZEMOVE -WM_EXITSIZEMOVE \ No newline at end of file +WM_EXITSIZEMOVE + +SetLastError +WINDOW_EX_STYLE \ No newline at end of file From dc07e762fe0abc147a71ea5e8cd8b156e3ad611e Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Fri, 14 Feb 2025 16:25:51 +0800 Subject: [PATCH 9/9] Add error handling for Get & SetWindowLong failure & Combine get style function --- Flow.Launcher/Helper/WindowsInteropHelper.cs | 33 +++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/Flow.Launcher/Helper/WindowsInteropHelper.cs b/Flow.Launcher/Helper/WindowsInteropHelper.cs index 4891bf41a..3e57948a5 100644 --- a/Flow.Launcher/Helper/WindowsInteropHelper.cs +++ b/Flow.Launcher/Helper/WindowsInteropHelper.cs @@ -151,16 +151,17 @@ public class WindowsInteropHelper #region Alt Tab - private static IntPtr SetWindowLong(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex, int dwNewLong) + private static int SetWindowLong(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex, int dwNewLong) { PInvoke.SetLastError(WIN32_ERROR.NO_ERROR); // Clear any existing error - return PInvoke.SetWindowLong(hWnd, nIndex, dwNewLong); - } + var result = PInvoke.SetWindowLong(hWnd, nIndex, dwNewLong); + if (result == 0 && Marshal.GetLastPInvokeError() != 0) + { + throw new Win32Exception(Marshal.GetLastPInvokeError()); + } - private static int IntPtrToInt32(IntPtr intPtr) - { - return unchecked((int)intPtr.ToInt64()); + return result; } /// @@ -169,13 +170,12 @@ public class WindowsInteropHelper /// To hide a window public static void HideFromAltTab(Window window) { - var helper = new WindowInteropHelper(window); - var exStyle = PInvoke.GetWindowLong(new(helper.Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE); + var exStyle = GetCurrentWindowStyle(window); // Add TOOLWINDOW style, remove APPWINDOW style var newExStyle = ((uint)exStyle | (uint)WINDOW_EX_STYLE.WS_EX_TOOLWINDOW) & ~(uint)WINDOW_EX_STYLE.WS_EX_APPWINDOW; - SetWindowLong(new(helper.Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, (int)newExStyle); + SetWindowLong(new(new WindowInteropHelper(window).Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, (int)newExStyle); } /// @@ -184,13 +184,12 @@ public class WindowsInteropHelper /// To restore the displayed window public static void ShowInAltTab(Window window) { - var helper = new WindowInteropHelper(window); - var exStyle = PInvoke.GetWindowLong(new(helper.Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE); + var exStyle = GetCurrentWindowStyle(window); // Remove the TOOLWINDOW style and add the APPWINDOW style. var newExStyle = ((uint)exStyle & ~(uint)WINDOW_EX_STYLE.WS_EX_TOOLWINDOW) | (uint)WINDOW_EX_STYLE.WS_EX_APPWINDOW; - SetWindowLong(new(helper.Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, (int)newExStyle); + SetWindowLong(new(new WindowInteropHelper(window).Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE, (int)newExStyle); } /// @@ -198,10 +197,14 @@ public class WindowsInteropHelper /// /// To obtain the style dialog window /// current extension style value - public static int GetCurrentWindowStyle(Window window) + private static int GetCurrentWindowStyle(Window window) { - var helper = new WindowInteropHelper(window); - return PInvoke.GetWindowLong(new(helper.Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE); + var style = PInvoke.GetWindowLong(new(new WindowInteropHelper(window).Handle), WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE); + if (style == 0 && Marshal.GetLastPInvokeError() != 0) + { + throw new Win32Exception(Marshal.GetLastPInvokeError()); + } + return style; } #endregion