From 134f916262a69916162a9139b88353d5218e5da9 Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Sat, 24 Oct 2020 16:51:48 +0200 Subject: [PATCH] Attempt of fixing more child window operations. --- .../Avalonia.Win32/Interop/UnmanagedMethods.cs | 6 ++++++ src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs index a527a35c52..f88c57cf59 100644 --- a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs +++ b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs @@ -1017,6 +1017,9 @@ namespace Avalonia.Win32.Interop [DllImport("user32.dll")] public static extern bool ValidateRect(IntPtr hWnd, IntPtr lpRect); + [DllImport("user32.dll")] + public static extern bool IsWindow(IntPtr hWnd); + [DllImport("user32.dll")] public static extern bool IsWindowEnabled(IntPtr hWnd); @@ -1050,6 +1053,9 @@ namespace Avalonia.Win32.Interop [DllImport("user32.dll")] public static extern bool ScreenToClient(IntPtr hWnd, ref POINT lpPoint); + [DllImport("user32.dll", SetLastError = true)] + public static extern IntPtr GetActiveWindow(); + [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr SetActiveWindow(IntPtr hWnd); diff --git a/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs b/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs index 1c66b9aae2..123472d23f 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs @@ -65,7 +65,17 @@ namespace Avalonia.Win32 return IntPtr.Zero; } - _parent?.SetEnabled(true); + if (_parent != null && IsWindow(_parent._hwnd)) + { + var wasActive = GetActiveWindow() == _hwnd; + + _parent.SetEnabled(true); + + if (wasActive) + { + SetActiveWindow(_parent._hwnd); + } + } break; }