mirror of
https://gitee.com/handyorg/HandyControl.git
synced 2024-11-29 18:38:30 +08:00
fix: get active window issue.
This commit is contained in:
parent
0e1fefa143
commit
5a1da60237
@ -20,7 +20,11 @@ public static class WindowHelper
|
||||
/// 获取当前应用中处于激活的一个窗口
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static Window GetActiveWindow() => Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
|
||||
public static Window GetActiveWindow()
|
||||
{
|
||||
var activeWindow = InteropMethods.GetActiveWindow();
|
||||
return Application.Current.Windows.OfType<Window>().FirstOrDefault(x => x.GetHandle() == activeWindow);
|
||||
}
|
||||
|
||||
private static readonly BitArray _cacheValid = new((int) InteropValues.CacheSlot.NumSlots);
|
||||
|
||||
|
@ -348,6 +348,9 @@ internal class InteropMethods
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
internal static extern IntPtr GetWindow(IntPtr hwnd, int nCmd);
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
internal static extern IntPtr GetActiveWindow();
|
||||
|
||||
[DllImport(InteropValues.ExternDll.User32)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
internal static extern bool IsWindowVisible(IntPtr hwnd);
|
||||
|
Loading…
Reference in New Issue
Block a user