Skip to content

Commit c5f383f

Browse files
committed
Fix some issues
1 parent 3499ed2 commit c5f383f

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

src/Shared/HandyControlDemo_Shared/UserControl/Controls/NotifyIconDemo.xaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<UserControl x:Class="HandyControlDemo.UserControl.NotifyIconDemo"
1+
<UserControl x:Class="HandyControlDemo.UserControl.NotifyIconDemo"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
@@ -54,6 +54,9 @@
5454
<hc:EventTrigger EventName="MouseDoubleClick">
5555
<hc:EventToCommand Command="{Binding MouseCmd}" CommandParameter="MouseDoubleClick"/>
5656
</hc:EventTrigger>
57+
<hc:EventTrigger EventName="BalloonTipClicked">
58+
<hc:EventToCommand Command="hc:ControlCommands.PushMainWindow2Top"/>
59+
</hc:EventTrigger>
5760
</hc:Interaction.Triggers>
5861
</hc:NotifyIcon>
5962
<hc:NotifyIcon Token="{x:Static data:MessageToken.NotifyIconContextDemo}" x:Name="NotifyIconContextContent" Text="HandyControl" IsBlink="{Binding ContextContentIsBlink}" Visibility="{Binding ContextContentIsShow,Converter={StaticResource Boolean2VisibilityConverter}}" Icon="/HandyControlDemo;component/Resources/Img/icon-white.ico">
@@ -75,6 +78,9 @@
7578
<hc:EventTrigger EventName="MouseDoubleClick">
7679
<hc:EventToCommand Command="{Binding MouseCmd}" CommandParameter="MouseDoubleClick"/>
7780
</hc:EventTrigger>
81+
<hc:EventTrigger EventName="BalloonTipClicked">
82+
<hc:EventToCommand Command="hc:ControlCommands.PushMainWindow2Top"/>
83+
</hc:EventTrigger>
7884
</hc:Interaction.Triggers>
7985
</hc:NotifyIcon>
8086
</hc:SimplePanel>

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ public class NotifyIcon : FrameworkElement, IDisposable
3636

3737
private const int WmTrayMouseMessage = InteropValues.WM_USER + 1024;
3838

39-
private const int NIN_BALLOONUSERCLICK = InteropValues.WM_USER + 1025;
40-
4139
private string _windowClassName;
4240

4341
private int _wmTaskbarCreated;
@@ -152,11 +150,12 @@ public void ShowBalloonTip(string title, string content, NotifyIconInfoType info
152150

153151
var data = new InteropValues.NOTIFYICONDATA
154152
{
155-
uFlags = InteropValues.NIF_INFO,
153+
uFlags = InteropValues.NIF_INFO | InteropValues.NIF_MESSAGE,
156154
hWnd = _messageWindowHandle,
157155
uID = _id,
158156
szInfoTitle = title ?? string.Empty,
159-
szInfo = content ?? string.Empty
157+
szInfo = content ?? string.Empty,
158+
uCallbackMessage = WmTrayMouseMessage
160159
};
161160

162161
data.dwInfoFlags = infoType switch
@@ -167,6 +166,7 @@ public void ShowBalloonTip(string title, string content, NotifyIconInfoType info
167166
NotifyIconInfoType.None => InteropValues.NIIF_NONE,
168167
_ => data.dwInfoFlags
169168
};
169+
data.dwInfoFlags |= InteropValues.NIIF_USER;
170170

171171
InteropMethods.Shell_NotifyIcon(InteropValues.NIM_MODIFY, data);
172172
}
@@ -577,7 +577,7 @@ private IntPtr Callback(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
577577
_dispatcherTimerPos.Start();
578578
}
579579
break;
580-
case NIN_BALLOONUSERCLICK:
580+
case InteropValues.NIN_BALLOONUSERCLICK:
581581
RaiseEvent(new RoutedEventArgs(BalloonTipClickedEvent));
582582
break;
583583
}
@@ -677,12 +677,13 @@ public event RoutedEventHandler MouseDoubleClick
677677
}
678678

679679
public static readonly RoutedEvent BalloonTipClickedEvent =
680-
EventManager.RegisterRoutedEvent("BalloonTipClicked", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(NotifyIcon));
680+
EventManager.RegisterRoutedEvent("BalloonTipClicked", RoutingStrategy.Bubble,
681+
typeof(RoutedEventHandler), typeof(NotifyIcon));
681682

682683
public event RoutedEventHandler BalloonTipClicked
683684
{
684-
add { AddHandler(BalloonTipClickedEvent, value); }
685-
remove { RemoveHandler(BalloonTipClickedEvent, value); }
685+
add => AddHandler(BalloonTipClickedEvent, value);
686+
remove => RemoveHandler(BalloonTipClickedEvent, value);
686687
}
687688

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

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Diagnostics.CodeAnalysis;
33
using System.IO;
44
using System.Runtime.InteropServices;
@@ -50,6 +50,7 @@ internal const int
5050
NIIF_INFO = 0x00000001,
5151
NIIF_WARNING = 0x00000002,
5252
NIIF_ERROR = 0x00000003,
53+
NIIF_USER = 0x00000004,
5354
WM_ACTIVATE = 0x0006,
5455
WM_QUIT = 0x0012,
5556
WM_GETMINMAXINFO = 0x0024,
@@ -98,7 +99,8 @@ internal const int
9899
SC_RESTORE = 0xF120,
99100
SRCCOPY = 0x00CC0020,
100101
MONITOR_DEFAULTTOPRIMARY = 0x00000001,
101-
MONITOR_DEFAULTTONEAREST = 0x00000002;
102+
MONITOR_DEFAULTTONEAREST = 0x00000002,
103+
NIN_BALLOONUSERCLICK = 0x0405;
102104

103105
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
104106
internal class NOTIFYICONDATA

0 commit comments

Comments
 (0)