Skip to content

Commit 64da563

Browse files
committed
refactor: NotifyIcon balloon tip event handling.
1 parent f5c5821 commit 64da563

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ public class NotifyIcon : FrameworkElement, IDisposable
3434

3535
private IconHandle _iconHandle;
3636

37-
private const int WmTrayMouseMessage = InteropValues.WM_USER + 1024;
38-
39-
private const int NIN_BALLOONUSERCLICK = InteropValues.WM_USER + 1025;
40-
4137
private string _windowClassName;
4238

4339
private int _wmTaskbarCreated;
@@ -494,7 +490,7 @@ private void UpdateIcon(bool showIconInTray, bool isTransparent = false)
494490
_isTransparent = isTransparent;
495491
var data = new InteropValues.NOTIFYICONDATA
496492
{
497-
uCallbackMessage = WmTrayMouseMessage,
493+
uCallbackMessage = InteropValues.WM_TRAYMOUSEMESSAGE,
498494
uFlags = InteropValues.NIF_MESSAGE | InteropValues.NIF_ICON | InteropValues.NIF_TIP,
499495
hWnd = _messageWindowHandle,
500496
uID = _id,
@@ -577,8 +573,8 @@ private IntPtr Callback(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
577573
_dispatcherTimerPos.Start();
578574
}
579575
break;
580-
case NIN_BALLOONUSERCLICK:
581-
RaiseEvent(new RoutedEventArgs(BalloonTipClickedEvent));
576+
case InteropValues.NIN_BALLOONUSERCLICK:
577+
RaiseEvent(new RoutedEventArgs(BalloonTipClickEvent));
582578
break;
583579
}
584580
}
@@ -676,13 +672,14 @@ public event RoutedEventHandler MouseDoubleClick
676672
remove => RemoveHandler(MouseDoubleClickEvent, value);
677673
}
678674

679-
public static readonly RoutedEvent BalloonTipClickedEvent =
680-
EventManager.RegisterRoutedEvent("BalloonTipClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(NotifyIcon));
675+
public static readonly RoutedEvent BalloonTipClickEvent =
676+
EventManager.RegisterRoutedEvent("BalloonTipClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler),
677+
typeof(NotifyIcon));
681678

682-
public event RoutedEventHandler BalloonTipClicked
679+
public event RoutedEventHandler BalloonTipClick
683680
{
684-
add { AddHandler(BalloonTipClickedEvent, value); }
685-
remove { RemoveHandler(BalloonTipClickedEvent, value); }
681+
add => AddHandler(BalloonTipClickEvent, value);
682+
remove => RemoveHandler(BalloonTipClickEvent, value);
686683
}
687684

688685
private void UpdateDataContext(FrameworkElement target, object oldValue, object newValue)

src/Shared/HandyControl_Shared/Tools/Interop/InteropValues.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ internal const int
8383
MF_BYPOSITION = 0x400,
8484
MF_GRAYED = 0x00000001,
8585
MF_SEPARATOR = 0x800,
86+
NIN_BALLOONUSERCLICK = WM_USER + 5,
8687
TB_GETBUTTON = WM_USER + 23,
8788
TB_BUTTONCOUNT = WM_USER + 24,
8889
TB_GETITEMRECT = WM_USER + 29,
90+
WM_TRAYMOUSEMESSAGE = WM_USER + 1024,
8991
VERTRES = 10,
9092
DESKTOPVERTRES = 117,
9193
LOGPIXELSX = 88,

0 commit comments

Comments
 (0)