Skip to content

Commit

Permalink
Merge pull request #113 from cairoshell/forward-post-msg
Browse files Browse the repository at this point in the history
  • Loading branch information
josuave authored Nov 14, 2024
2 parents ff8cc1b + 5103220 commit 26c6c87
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ManagedShell.Interop/NativeMethods.User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/ManagedShell.WindowsTray/TrayService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 26c6c87

Please sign in to comment.