Browse Source

Add a bunch of comments to explain what is going on in win32 closed handler.

pull/4928/head
Dariusz Komosinski 6 years ago
parent
commit
27ee4e00cd
  1. 6
      src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs

6
src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs

@ -65,12 +65,18 @@ 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);

Loading…
Cancel
Save