@@ -94,6 +94,12 @@ public class WindowMessageSink : IDisposable
9494 /// </summary>
9595 public event Action < MouseEvent > MouseEventReceived ;
9696
97+ /// <summary>
98+ /// Fired in case the user uses the WM_CONTEXTMENU-key
99+ /// on the taskbar icon.
100+ /// </summary>
101+ public event Action < Point > ContextMenuReceived ;
102+
97103 /// <summary>
98104 /// Fired if a balloon ToolTip was either displayed
99105 /// or closed (indicated by the boolean flag).
@@ -242,8 +248,19 @@ private void ProcessWindowMessage(uint msg, IntPtr wParam, IntPtr lParam)
242248 switch ( message )
243249 {
244250 case WindowsMessages . WM_CONTEXTMENU :
245- // TODO: Handle WM_CONTEXTMENU, see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
246- Debug . WriteLine ( "Unhandled WM_CONTEXTMENU" ) ;
251+ case WindowsMessages . NIN_SELECT :
252+ case WindowsMessages . NIN_KEYSELECT :
253+ /*
254+ * GET_X_LPARAM should be used to retrieve anchor X-coordinate, this is defined as
255+ * ((int)(short)((WORD)(((ULONG_PTR)(wParam)) & 0xffff)))
256+ * GET_Y_LPARAM should be used to retrieve anchor Y-coordinate, this is defined as
257+ * ((int)(short)((WORD)((((ULONG_PTR)(wParam)) >> 16) & 0xffff)))
258+ */
259+ ContextMenuReceived ? . Invoke ( new Point ( )
260+ {
261+ X = ( short ) ( ( nint ) wParam & 0xFFFF ) ,
262+ Y = ( short ) ( ( nint ) wParam >> 16 & 0xFFFF )
263+ } ) ;
247264 break ;
248265
249266 case WindowsMessages . WM_MOUSEMOVE :
@@ -312,16 +329,6 @@ private void ProcessWindowMessage(uint msg, IntPtr wParam, IntPtr lParam)
312329 ChangeToolTipStateRequest ? . Invoke ( false ) ;
313330 break ;
314331
315- case WindowsMessages . NIN_SELECT :
316- // TODO: Handle NIN_SELECT see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
317- Debug . WriteLine ( "Unhandled NIN_SELECT" ) ;
318- break ;
319-
320- case WindowsMessages . NIN_KEYSELECT :
321- // TODO: Handle NIN_KEYSELECT see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
322- Debug . WriteLine ( "Unhandled NIN_KEYSELECT" ) ;
323- break ;
324-
325332 default :
326333 Debug . WriteLine ( "Unhandled NotifyIcon message ID: " + lParam ) ;
327334 break ;
0 commit comments