diff --git a/src/ManagedShell.Interop/NativeMethods.User32.cs b/src/ManagedShell.Interop/NativeMethods.User32.cs index 154bfb1b..e476dc48 100644 --- a/src/ManagedShell.Interop/NativeMethods.User32.cs +++ b/src/ManagedShell.Interop/NativeMethods.User32.cs @@ -3014,6 +3014,9 @@ public static extern IntPtr CreateWindowEx( [DllImport(User32_DllName)] public static extern bool PostMessage(int hWnd, uint msg, int wParam, long lParam); + [DllImport(User32_DllName)] + public static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); + public enum KLF : uint { ACTIVATE = 0x00000001, diff --git a/src/ManagedShell.WindowsTray/TrayService.cs b/src/ManagedShell.WindowsTray/TrayService.cs index 254af926..de1e0e35 100644 --- a/src/ManagedShell.WindowsTray/TrayService.cs +++ b/src/ManagedShell.WindowsTray/TrayService.cs @@ -1,6 +1,7 @@ using ManagedShell.Common.Helpers; using ManagedShell.Common.Logging; using System; +using System.Linq; using System.Runtime.InteropServices; using System.Windows.Threading; using static ManagedShell.Interop.NativeMethods; @@ -11,6 +12,7 @@ public class TrayService : IDisposable { private const string NotifyWndClass = "TrayNotifyWnd"; private const string TrayWndClass = "Shell_TrayWnd"; + private readonly int[] ForwardMessagesPost = { (int)WM.USER + 372 }; private AppBarMessageDelegate appBarMessageDelegate; private IconDataDelegate iconDataDelegate; @@ -267,6 +269,12 @@ private IntPtr ForwardMsg(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) if (HwndFwd != IntPtr.Zero) { + if (msg >= (int)WM.USER && ForwardMessagesPost.Contains(msg)) + { + ShellLogger.Debug($"TrayService: Forwarding message via PostMessage: {msg}"); + PostMessage(HwndFwd, (uint)msg, wParam, lParam); + return DefWindowProc(hWnd, msg, wParam, lParam); + } return SendMessage(HwndFwd, msg, wParam, lParam); }