[Refactor]Use same improved BringToForeground across the solution (#28532)

* Use single BringToForeground across the solution

* Close flyout manually

* Try with sending input, if it fails try threads
This commit is contained in:
Stefan Markovic
2023-10-23 18:16:11 +02:00
committed by GitHub
parent f718bef45c
commit 6a092548b1
13 changed files with 95 additions and 109 deletions

View File

@@ -22,19 +22,6 @@ namespace Peek.UI.Extensions
return hwnd.GetMonitorScale();
}
public static void BringToForeground(this Window window)
{
// Ability to be able to set the Window to the Foreground is very limited. A current workaround is simulating mouse input before bringing to the foreground.
var windowHandle = window.GetWindowHandle();
Windows.Win32.UI.Input.KeyboardAndMouse.INPUT input = new Windows.Win32.UI.Input.KeyboardAndMouse.INPUT { type = Windows.Win32.UI.Input.KeyboardAndMouse.INPUT_TYPE.INPUT_MOUSE, Anonymous = { } };
Windows.Win32.UI.Input.KeyboardAndMouse.INPUT[] inputs = new Windows.Win32.UI.Input.KeyboardAndMouse.INPUT[] { input };
_ = PInvoke.SendInput(inputs.AsSpan<Windows.Win32.UI.Input.KeyboardAndMouse.INPUT>(), Marshal.SizeOf(typeof(Windows.Win32.UI.Input.KeyboardAndMouse.INPUT)));
if (PInvoke.SetForegroundWindow(new HWND(windowHandle)) == 0)
{
Logger.LogWarning("Couldn't set the Peek window as the foreground window.");
}
}
internal static void CenterOnMonitor(this Window window, HWND hwndDesktop, double? width = null, double? height = null)
{
var hwndToCenter = new HWND(window.GetWindowHandle());

View File

@@ -4,7 +4,6 @@ GetDpiForWindow
GetForegroundWindow
SetForegroundWindow
SetActiveWindow
SendInput
GetWindowThreadProcessId
GetCurrentThreadId
AttachThreadInput

View File

@@ -184,7 +184,7 @@ namespace Peek.UI
}
this.Show();
this.BringToForeground();
WindowHelpers.BringToForeground(this.GetWindowHandle());
}
private Size GetMonitorMaxContentSize(Size monitorSize, double scaling)