From f4366ded896501694c26059ac6f6ef9db20bfb46 Mon Sep 17 00:00:00 2001 From: mpondo <565423+mpondo@users.noreply.github.com> Date: Wed, 14 Jul 2021 14:12:48 -0400 Subject: [PATCH] Fix close from taskbar for floating window --- .../LayoutDocumentFloatingWindowControl.cs | 14 +++++++++++++- source/Components/AvalonDock/Win32Helper.cs | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs b/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs index b88c016c..8cb81a9d 100644 --- a/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs +++ b/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs @@ -1,4 +1,4 @@ -/************************************************************************ +/************************************************************************ AvalonDock Copyright (C) 2007-2013 Xceed Software Inc. @@ -16,6 +16,7 @@ This program is provided to you under the terms of the Microsoft Public using System.Windows; using System.Windows.Controls.Primitives; using System.Windows.Input; +using System.Windows.Interop; namespace AvalonDock.Controls { @@ -142,6 +143,17 @@ protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, Int WindowChrome.GetWindowChrome(this).ShowSystemMenu = false; } break; + + case Win32Helper.WM_CLOSE: + if (CloseInitiatedByUser) + { + // We want to force the window to go through our standard logic for closing. + // So, if the window close is initiated outside of our code (such as from the taskbar), + // we cancel that close and trigger our close logic instead. + this.CloseWindowCommand.Execute(null); + handled = true; + } + break; } return base.FilterMessage(hwnd, msg, wParam, lParam, ref handled); } diff --git a/source/Components/AvalonDock/Win32Helper.cs b/source/Components/AvalonDock/Win32Helper.cs index ce2cc9dc..607db494 100644 --- a/source/Components/AvalonDock/Win32Helper.cs +++ b/source/Components/AvalonDock/Win32Helper.cs @@ -1,4 +1,4 @@ -/************************************************************************ +/************************************************************************ AvalonDock Copyright (C) 2007-2013 Xceed Software Inc. @@ -153,6 +153,7 @@ internal class WINDOWPOS internal const int WM_INITMENUPOPUP = 0x0117; internal const int WM_KEYDOWN = 0x0100; internal const int WM_KEYUP = 0x0101; + internal const int WM_CLOSE = 0x10; internal const int WA_INACTIVE = 0x0000;