14
14
15
15
namespace HandyControl . Tools ;
16
16
17
- public static class WindowHelper
17
+ public static partial class WindowHelper
18
18
{
19
19
/// <summary>
20
- /// 获取当前应用中处于激活的一个窗口
20
+ /// Get the active window in the current application
21
21
/// </summary>
22
22
/// <returns></returns>
23
23
public static Window GetActiveWindow ( ) => Application . Current . Windows . OfType < Window > ( ) . SingleOrDefault ( x => x . IsActive ) ;
@@ -145,7 +145,7 @@ public static Thickness WindowMaximizedPadding
145
145
InteropMethods . ReleaseDC ( IntPtr . Zero , hdc ) ;
146
146
return WindowResizeBorderThickness . Add ( new Thickness ( ( autoHide ? - 4 : 4 ) * scale ) ) ;
147
147
#else
148
- return WindowResizeBorderThickness . Add ( new Thickness ( autoHide ? - 4 : 4 ) ) ;
148
+ return WindowResizeBorderThickness . Add ( new Thickness ( autoHide ? - 4 : 4 ) ) ;
149
149
#endif
150
150
}
151
151
}
@@ -157,12 +157,12 @@ public static Thickness WindowMaximizedPadding
157
157
public static HwndSource GetHwndSource ( this Window window ) => HwndSource . FromHwnd ( window . GetHandle ( ) ) ;
158
158
159
159
/// <summary>
160
- /// 让窗口激活作为前台最上层窗口
160
+ /// Make the window active as the topmost window in the foreground
161
161
/// </summary>
162
162
/// <param name="window"></param>
163
163
public static void SetWindowToForeground ( Window window )
164
164
{
165
- // [WPF 让窗口激活作为前台最上层窗口的方法 - lindexi - 博客园 ](https://www.cnblogs.com/lindexi/p/12749671.html)
165
+ // [WPF Make the window active as the uppermost window in the foreground - lindexi - Blog ](https://www.cnblogs.com/lindexi/p/12749671.html)
166
166
var interopHelper = new WindowInteropHelper ( window ) ;
167
167
var thisWindowThreadId = InteropMethods . GetWindowThreadProcessId ( interopHelper . Handle , out _ ) ;
168
168
var currentForegroundWindow = InteropMethods . GetForegroundWindow ( ) ;
@@ -171,11 +171,11 @@ public static void SetWindowToForeground(Window window)
171
171
// [c# - Bring a window to the front in WPF - Stack Overflow](https://stackoverflow.com/questions/257587/bring-a-window-to-the-front-in-wpf )
172
172
// [SetForegroundWindow的正确用法 - 子坞 - 博客园](https://www.cnblogs.com/ziwuge/archive/2012/01/06/2315342.html )
173
173
/*
174
- 1.得到窗口句柄FindWindow
175
- 2.切换键盘输入焦点AttachThreadInput
176
- 3.显示窗口ShowWindow(有些窗口被最小化/隐藏了)
177
- 4.更改窗口的Z Order,SetWindowPos使之最上,为了不影响后续窗口的Z Order,改完之后,再还原
178
- 5.最后SetForegroundWindow
174
+ 1.得到窗口句柄FindWindow
175
+ 2.切换键盘输入焦点AttachThreadInput
176
+ 3.显示窗口ShowWindow(有些窗口被最小化/隐藏了)
177
+ 4.更改窗口的Z Order,SetWindowPos使之最上,为了不影响后续窗口的Z Order,改完之后,再还原
178
+ 5.最后SetForegroundWindow
179
179
*/
180
180
181
181
InteropMethods . AttachThreadInput ( currentForegroundWindowThreadId , thisWindowThreadId , true ) ;
0 commit comments