From ad09dfffe7a03cae0753eeb727c602253723043a Mon Sep 17 00:00:00 2001 From: Noisrev Date: Mon, 31 Oct 2022 21:43:41 +0800 Subject: [PATCH 1/2] Add Null check for GetWindowChrome --- .../LayoutAnchorableFloatingWindowControl.cs | 7 ++++++- .../Controls/LayoutDocumentFloatingWindowControl.cs | 13 +++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs b/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs index 8f84e548..98b4f87f 100644 --- a/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs +++ b/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs @@ -257,7 +257,12 @@ protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, Int if (wParam.ToInt32() == Win32Helper.HT_CAPTION) { if (OpenContextMenu()) handled = true; - WindowChrome.GetWindowChrome(this).ShowSystemMenu = _model.Root.Manager.ShowSystemMenu && !handled; + + var windowChrome = WindowChrome.GetWindowChrome(this); + if (windowChrome != null) + { + windowChrome.ShowSystemMenu = _model.Root.Manager.ShowSystemMenu && !handled; + } } break; } diff --git a/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs b/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs index c394fbea..057da3d7 100644 --- a/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs +++ b/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs @@ -137,10 +137,15 @@ protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, Int { if (OpenContextMenu()) handled = true; - if (_model.Root.Manager.ShowSystemMenu) - WindowChrome.GetWindowChrome(this).ShowSystemMenu = !handled; - else - WindowChrome.GetWindowChrome(this).ShowSystemMenu = false; + + var windowChrome = WindowChrome.GetWindowChrome(this); + if (windowChrome != null) + { + if (_model.Root.Manager.ShowSystemMenu) + windowChrome.ShowSystemMenu = !handled; + else + windowChrome.ShowSystemMenu = false; + } } break; From e77aaaf717add5d67e37c9b370a9034727f4e93e Mon Sep 17 00:00:00 2001 From: Noisrev Date: Tue, 1 Nov 2022 18:03:34 +0800 Subject: [PATCH 2/2] Move OpenContextMenu after GetWindowChrome --- .../Controls/LayoutAnchorableFloatingWindowControl.cs | 3 +-- .../Controls/LayoutDocumentFloatingWindowControl.cs | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs b/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs index 98b4f87f..5e238fa3 100644 --- a/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs +++ b/source/Components/AvalonDock/Controls/LayoutAnchorableFloatingWindowControl.cs @@ -256,11 +256,10 @@ protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, Int case Win32Helper.WM_NCRBUTTONUP: if (wParam.ToInt32() == Win32Helper.HT_CAPTION) { - if (OpenContextMenu()) handled = true; - var windowChrome = WindowChrome.GetWindowChrome(this); if (windowChrome != null) { + if (OpenContextMenu()) handled = true; windowChrome.ShowSystemMenu = _model.Root.Manager.ShowSystemMenu && !handled; } } diff --git a/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs b/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs index 057da3d7..92f96376 100644 --- a/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs +++ b/source/Components/AvalonDock/Controls/LayoutDocumentFloatingWindowControl.cs @@ -135,12 +135,12 @@ protected override IntPtr FilterMessage(IntPtr hwnd, int msg, IntPtr wParam, Int case Win32Helper.WM_NCRBUTTONUP: if (wParam.ToInt32() == Win32Helper.HT_CAPTION) { - if (OpenContextMenu()) - handled = true; - var windowChrome = WindowChrome.GetWindowChrome(this); if (windowChrome != null) { + if (OpenContextMenu()) + handled = true; + if (_model.Root.Manager.ShowSystemMenu) windowChrome.ShowSystemMenu = !handled; else