From 194e4ec4567373f482313eb5f25f82166f8ba200 Mon Sep 17 00:00:00 2001 From: Ashish Kumar Singh Date: Mon, 7 Feb 2022 18:13:41 +0530 Subject: [PATCH] preserve extra info across PeekMessage (#5838) (#6001) Co-authored-by: Sam Bent --- .../src/Shared/MS/Win32/UnsafeNativeMethodsOther.cs | 4 +++- .../src/WindowsBase/System/Windows/Threading/Dispatcher.cs | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsOther.cs b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsOther.cs index 5f0d758f9..358e053fd 100644 --- a/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsOther.cs +++ b/src/Microsoft.DotNet.Wpf/src/Shared/MS/Win32/UnsafeNativeMethodsOther.cs @@ -187,9 +187,11 @@ internal interface IInternetSecurityManager #if BASE_NATIVEMETHODS - [DllImport(ExternDll.User32, CharSet = CharSet.Auto)] internal static extern IntPtr GetMessageExtraInfo(); + + [DllImport(ExternDll.User32, CharSet = CharSet.Auto)] + internal static extern IntPtr SetMessageExtraInfo(IntPtr lParam); #endif #if BASE_NATIVEMETHODS diff --git a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs index f87a32dee..90728a102 100644 --- a/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs +++ b/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Windows/Threading/Dispatcher.cs @@ -2417,8 +2417,14 @@ internal bool CriticalRequestProcessing(bool force) } else if (_postedProcessingType == PROCESS_FOREGROUND) { + // Preserve the thread's current "extra message info" + // (PeekMessage overwrites it). + IntPtr extraInformation = UnsafeNativeMethods.GetMessageExtraInfo(); + MSG msg = new MSG(); UnsafeNativeMethods.PeekMessage(ref msg, new HandleRef(this, _window.Value.Handle), _msgProcessQueue, _msgProcessQueue, NativeMethods.PM_REMOVE); + + UnsafeNativeMethods.SetMessageExtraInfo(extraInformation); } _postedProcessingType = PROCESS_NONE; } -- GitLab