@@ -94,6 +94,12 @@ public class WindowMessageSink : IDisposable
94
94
/// </summary>
95
95
public event Action < MouseEvent > MouseEventReceived ;
96
96
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
+
97
103
/// <summary>
98
104
/// Fired if a balloon ToolTip was either displayed
99
105
/// or closed (indicated by the boolean flag).
@@ -242,8 +248,19 @@ private void ProcessWindowMessage(uint msg, IntPtr wParam, IntPtr lParam)
242
248
switch ( message )
243
249
{
244
250
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
+ } ) ;
247
264
break ;
248
265
249
266
case WindowsMessages . WM_MOUSEMOVE :
@@ -312,16 +329,6 @@ private void ProcessWindowMessage(uint msg, IntPtr wParam, IntPtr lParam)
312
329
ChangeToolTipStateRequest ? . Invoke ( false ) ;
313
330
break ;
314
331
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
-
325
332
default :
326
333
Debug . WriteLine ( "Unhandled NotifyIcon message ID: " + lParam ) ;
327
334
break ;
0 commit comments