Browse Source
Merge pull request #4928 from MarchingCube/fix-win32-dialog-minimizing-parent
Fix closing dialog windows on win32 causing parent window to be moved to back
pull/4934/head
danwalmsley
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
24 additions and
0 deletions
-
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
-
src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.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); |
|
|
|
|
|
|
|
|
|
|
|
@ -65,6 +65,24 @@ namespace Avalonia.Win32 |
|
|
|
return IntPtr.Zero; |
|
|
|
} |
|
|
|
|
|
|
|
// Based on https://github.com/dotnet/wpf/blob/master/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Window.cs#L4270-L4337
|
|
|
|
// We need to enable parent window before destroying child window to prevent OS from activating a random window behind us.
|
|
|
|
// This is described here: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enablewindow#remarks
|
|
|
|
// Our window closed callback will set enabled state to a correct value after child window gets destroyed.
|
|
|
|
// We need to verify if parent is still alive (perhaps it got destroyed somehow).
|
|
|
|
if (_parent != null && IsWindow(_parent._hwnd)) |
|
|
|
{ |
|
|
|
var wasActive = GetActiveWindow() == _hwnd; |
|
|
|
|
|
|
|
_parent.SetEnabled(true); |
|
|
|
|
|
|
|
// We also need to activate our parent window since again OS might try to activate a window behind if it is not set.
|
|
|
|
if (wasActive) |
|
|
|
{ |
|
|
|
SetActiveWindow(_parent._hwnd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
|