Skip to content

Implement WM_ContextMenu #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions src/NotifyIconWpf/Interop/WindowMessageSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ public class WindowMessageSink : IDisposable
/// </summary>
public event Action<MouseEvent> MouseEventReceived;

/// <summary>
/// Fired in case the user uses the WM_CONTEXTMENU-key
/// on the taskbar icon.
/// </summary>
public event Action<Point> ContextMenuReceived;

/// <summary>
/// Fired if a balloon ToolTip was either displayed
/// or closed (indicated by the boolean flag).
Expand Down Expand Up @@ -242,8 +248,19 @@ private void ProcessWindowMessage(uint msg, IntPtr wParam, IntPtr lParam)
switch (message)
{
case WindowsMessages.WM_CONTEXTMENU:
// TODO: Handle WM_CONTEXTMENU, see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
Debug.WriteLine("Unhandled WM_CONTEXTMENU");
case WindowsMessages.NIN_SELECT:
case WindowsMessages.NIN_KEYSELECT:
/*
* GET_X_LPARAM should be used to retrieve anchor X-coordinate, this is defined as
* ((int)(short)((WORD)(((ULONG_PTR)(wParam)) & 0xffff)))
* GET_Y_LPARAM should be used to retrieve anchor Y-coordinate, this is defined as
* ((int)(short)((WORD)((((ULONG_PTR)(wParam)) >> 16) & 0xffff)))
*/
ContextMenuReceived?.Invoke(new Point()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the other comment, why not place the code to do the low / high bit logic directly here, as it's probably not used elsewhere.

{
X = (short)((nint)wParam & 0xFFFF),
Y = (short)((nint)wParam >> 16 & 0xFFFF)
});
break;

case WindowsMessages.WM_MOUSEMOVE:
Expand Down Expand Up @@ -312,16 +329,6 @@ private void ProcessWindowMessage(uint msg, IntPtr wParam, IntPtr lParam)
ChangeToolTipStateRequest?.Invoke(false);
break;

case WindowsMessages.NIN_SELECT:
// TODO: Handle NIN_SELECT see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
Debug.WriteLine("Unhandled NIN_SELECT");
break;

case WindowsMessages.NIN_KEYSELECT:
// TODO: Handle NIN_KEYSELECT see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
Debug.WriteLine("Unhandled NIN_KEYSELECT");
break;

default:
Debug.WriteLine("Unhandled NotifyIcon message ID: " + lParam);
break;
Expand Down
1 change: 1 addition & 0 deletions src/NotifyIconWpf/TaskbarIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public TaskbarIcon()

// register event listeners
messageSink.MouseEventReceived += OnMouseEvent;
messageSink.ContextMenuReceived += ShowContextMenu;
messageSink.TaskbarCreated += OnTaskbarCreated;
messageSink.ChangeToolTipStateRequest += OnToolTipChange;
messageSink.BalloonToolTipChanged += OnBalloonToolTipChanged;
Expand Down