-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Fixed issue where window wasn't always brought to foreground (#1…
- Loading branch information
Showing
4 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Files.App/Helpers/Win32/Win32Helper.WindowManagement.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using Windows.Win32; | ||
using Windows.Win32.UI.WindowsAndMessaging; | ||
|
||
namespace Files.App.Helpers | ||
{ | ||
public static partial class Win32Helper | ||
{ | ||
/// <summary> | ||
/// Brings the app window to foreground. | ||
/// </summary> | ||
/// <remarks> | ||
/// For more information, visit | ||
/// <br/> | ||
/// - <a href="https://stackoverflow.com/questions/1544179/what-are-the-differences-between-bringwindowtotop-setforegroundwindow-setwindo" /> | ||
/// <br/> | ||
/// - <a href="https://stackoverflow.com/questions/916259/win32-bring-a-window-to-top" /> | ||
/// </remarks> | ||
/// <param name="hWnd">The window handle to bring.</param> | ||
public static unsafe void BringToForegroundEx(Windows.Win32.Foundation.HWND hWnd) | ||
{ | ||
var hCurWnd = PInvoke.GetForegroundWindow(); | ||
var dwMyID = PInvoke.GetCurrentThreadId(); | ||
var dwCurID = PInvoke.GetWindowThreadProcessId(hCurWnd); | ||
|
||
PInvoke.AttachThreadInput(dwCurID, dwMyID, true); | ||
|
||
PInvoke.SetWindowPos(hWnd, (Windows.Win32.Foundation.HWND)(-1), 0, 0, 0, 0, SET_WINDOW_POS_FLAGS.SWP_NOSIZE | SET_WINDOW_POS_FLAGS.SWP_NOMOVE); | ||
PInvoke.SetWindowPos(hWnd, (Windows.Win32.Foundation.HWND)(-2), 0, 0, 0, 0, SET_WINDOW_POS_FLAGS.SWP_SHOWWINDOW | SET_WINDOW_POS_FLAGS.SWP_NOSIZE | SET_WINDOW_POS_FLAGS.SWP_NOMOVE); | ||
PInvoke.SetForegroundWindow(hWnd); | ||
PInvoke.SetFocus(hWnd); | ||
PInvoke.SetActiveWindow(hWnd); | ||
PInvoke.AttachThreadInput(dwCurID, dwMyID, false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters