update PushMainWindow2TopCommand
This commit is contained in:
1 parent
7151fec7b8
commit
652bdf918e
2 files changed
+4
-11
No files matched your search
@@ -1,8 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Interop;
|
using HandyControl.Tools;
|
||||||
using HandyControl.Tools.Interop;
|
|
||||||
|
|
||||||
namespace HandyControl.Interactivity
|
namespace HandyControl.Interactivity
|
||||||
{
|
{
|
||||||
@@ -15,11 +14,7 @@ namespace HandyControl.Interactivity
|
|||||||
if (Application.Current.MainWindow != null && Application.Current.MainWindow.Visibility != Visibility.Visible)
|
if (Application.Current.MainWindow != null && Application.Current.MainWindow.Visibility != Visibility.Visible)
|
||||||
{
|
{
|
||||||
Application.Current.MainWindow.Show();
|
Application.Current.MainWindow.Show();
|
||||||
var hwndSource = (HwndSource)PresentationSource.FromDependencyObject(Application.Current.MainWindow);
|
WindowHelper.SetWindowToForeground(Application.Current.MainWindow);
|
||||||
if (hwndSource != null)
|
|
||||||
{
|
|
||||||
InteropMethods.SetForegroundWindow(hwndSource.Handle);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,15 +157,13 @@ namespace HandyControl.Tools
|
|||||||
/// 让窗口激活作为前台最上层窗口
|
/// 让窗口激活作为前台最上层窗口
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="window"></param>
|
/// <param name="window"></param>
|
||||||
public static void SetWindowToForegroundWithAttachThreadInput(Window window)
|
public static void SetWindowToForeground(Window window)
|
||||||
{
|
{
|
||||||
// [WPF 让窗口激活作为前台最上层窗口的方法 - lindexi - 博客园](https://www.cnblogs.com/lindexi/p/12749671.html)
|
// [WPF 让窗口激活作为前台最上层窗口的方法 - lindexi - 博客园](https://www.cnblogs.com/lindexi/p/12749671.html)
|
||||||
var interopHelper = new WindowInteropHelper(window);
|
var interopHelper = new WindowInteropHelper(window);
|
||||||
// 以下 Win32 方法可以在 https://github.com/kkwpsv/lsjutil/tree/master/Src/Lsj.Util.Win32 找到
|
|
||||||
var thisWindowThreadId = InteropMethods.GetWindowThreadProcessId(interopHelper.Handle, out _);
|
var thisWindowThreadId = InteropMethods.GetWindowThreadProcessId(interopHelper.Handle, out _);
|
||||||
var currentForegroundWindow = InteropMethods.GetForegroundWindow();
|
var currentForegroundWindow = InteropMethods.GetForegroundWindow();
|
||||||
var currentForegroundWindowThreadId =
|
var currentForegroundWindowThreadId = InteropMethods.GetWindowThreadProcessId(currentForegroundWindow, out _);
|
||||||
InteropMethods.GetWindowThreadProcessId(currentForegroundWindow, out _);
|
|
||||||
|
|
||||||
// [c# - Bring a window to the front in WPF - Stack Overflow](https://stackoverflow.com/questions/257587/bring-a-window-to-the-front-in-wpf )
|
// [c# - Bring a window to the front in WPF - Stack Overflow](https://stackoverflow.com/questions/257587/bring-a-window-to-the-front-in-wpf )
|
||||||
// [SetForegroundWindow的正确用法 - 子坞 - 博客园](https://www.cnblogs.com/ziwuge/archive/2012/01/06/2315342.html )
|
// [SetForegroundWindow的正确用法 - 子坞 - 博客园](https://www.cnblogs.com/ziwuge/archive/2012/01/06/2315342.html )
|
||||||
|
|||||||
Reference in new issue
Block a user