Skip to content

Commit 652bdf9

Browse files
committed
update PushMainWindow2TopCommand
1 parent 7151fec commit 652bdf9

2 files changed

Lines changed: 4 additions & 11 deletions

File tree

src/Shared/HandyControl_Shared/Interactivity/Commands/PushMainWindow2TopCommand.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using System;
22
using System.Windows;
33
using System.Windows.Input;
4-
using System.Windows.Interop;
5-
using HandyControl.Tools.Interop;
4+
using HandyControl.Tools;
65

76
namespace HandyControl.Interactivity
87
{
@@ -15,11 +14,7 @@ public void Execute(object parameter)
1514
if (Application.Current.MainWindow != null && Application.Current.MainWindow.Visibility != Visibility.Visible)
1615
{
1716
Application.Current.MainWindow.Show();
18-
var hwndSource = (HwndSource)PresentationSource.FromDependencyObject(Application.Current.MainWindow);
19-
if (hwndSource != null)
20-
{
21-
InteropMethods.SetForegroundWindow(hwndSource.Handle);
22-
}
17+
WindowHelper.SetWindowToForeground(Application.Current.MainWindow);
2318
}
2419
}
2520

src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,13 @@ public static Thickness WindowMaximizedPadding
157157
/// 让窗口激活作为前台最上层窗口
158158
/// </summary>
159159
/// <param name="window"></param>
160-
public static void SetWindowToForegroundWithAttachThreadInput(Window window)
160+
public static void SetWindowToForeground(Window window)
161161
{
162162
// [WPF 让窗口激活作为前台最上层窗口的方法 - lindexi - 博客园](https://www.cnblogs.com/lindexi/p/12749671.html)
163163
var interopHelper = new WindowInteropHelper(window);
164-
// 以下 Win32 方法可以在 https://github.com/kkwpsv/lsjutil/tree/master/Src/Lsj.Util.Win32 找到
165164
var thisWindowThreadId = InteropMethods.GetWindowThreadProcessId(interopHelper.Handle, out _);
166165
var currentForegroundWindow = InteropMethods.GetForegroundWindow();
167-
var currentForegroundWindowThreadId =
168-
InteropMethods.GetWindowThreadProcessId(currentForegroundWindow, out _);
166+
var currentForegroundWindowThreadId = InteropMethods.GetWindowThreadProcessId(currentForegroundWindow, out _);
169167

170168
// [c# - Bring a window to the front in WPF - Stack Overflow](https://stackoverflow.com/questions/257587/bring-a-window-to-the-front-in-wpf )
171169
// [SetForegroundWindow的正确用法 - 子坞 - 博客园](https://www.cnblogs.com/ziwuge/archive/2012/01/06/2315342.html )

0 commit comments

Comments
 (0)