/
githubmirror
/
Files
Обзор
Документация
Войти
/
githubmirror
/
Files
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Files.App/Helpers/Win32/Win32Helper.WindowManagement.cs
61 строка
2 KB
yair100
Fix: Fixed issue where clicking selected file would switch focus to the main window (#18706)
12 июл 2026, 23:25
Не верифицирован
12 июл 2026, 23:25
da5dcd9
Код
Авторство
О чём код?
// Copyright (c) 2024 Files Community // Licensed under the MIT License. See the LICENSE. using System.Runtime.InteropServices; using Windows.Win32; using Windows.Win32.UI.WindowsAndMessaging; namespace Files.App.Helpers { /// <summary> /// Provides static helper for Win32. /// </summary> 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(); // Nothing to do if we already are the foreground window. Running the rest // unconditionally calls SetFocus(hWnd) on the top-level HWND, which drops // XAML focus to the window root and breaks arrow-key navigation after a // click on a non-name column of a selected Details-layout row. if (hCurWnd == hWnd) return; 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); } /// <summary> /// Force window to stay at bottom of other upper windows. /// </summary> /// <param name="lParam">The lParam of the message.</param> public static void ForceWindowPosition(nint lParam) { var windowPos = Marshal.PtrToStructure<WINDOWPOS>(lParam); windowPos.flags |= SET_WINDOW_POS_FLAGS.SWP_NOZORDER; Marshal.StructureToPtr(windowPos, lParam, false); } } }