From bf46f207042064e22189a1487008dd3b5d8eba2d Mon Sep 17 00:00:00 2001 From: Liu Zhenpeng <1040063186@qq.com> Date: Tue, 10 Sep 2019 16:19:11 +0800 Subject: [PATCH 1/4] add ShowBalloonTip --- .../Controls/Other/NotifyIcon.cs | 34 ++++++++++++++++++- .../Data/Enum/ToolTipIcon.cs | 25 ++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/Shared/HandyControl_Shared/Data/Enum/ToolTipIcon.cs diff --git a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs index f9b072f9..80da1670 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs @@ -165,7 +165,39 @@ namespace HandyControl.Controls public static readonly DependencyProperty IsBlinkProperty = DependencyProperty.Register( "IsBlink", typeof(bool), typeof(NotifyIcon), new PropertyMetadata(ValueBoxes.FalseBox, OnIsBlinkChanged)); - private static void OnIsBlinkChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + public void ShowBalloonTip(string tipTitle, string tipText, ToolTipIcon tipIcon) + { + if (DesignerHelper.IsInDesignMode) return; + + var data = new NOTIFYICONDATA + { + hWnd = _messageWindowHandle, + uID = _id, + uFlags = NativeMethods.NIF_INFO, + dwInfoFlags = NativeMethods.NIF_TIP, + szInfoTitle = tipTitle ?? string.Empty, + szInfo = tipText ?? string.Empty, + }; + + switch (tipIcon) + { + case ToolTipIcon.Info: + data.dwInfoFlags = NativeMethods.NIIF_INFO; + break; + case ToolTipIcon.Warning: + data.dwInfoFlags = NativeMethods.NIIF_WARNING; + break; + case ToolTipIcon.Error: + data.dwInfoFlags = NativeMethods.NIIF_ERROR; + break; + case ToolTipIcon.None: + data.dwInfoFlags = NativeMethods.NIIF_NONE; + break; + } + UnsafeNativeMethods.Shell_NotifyIcon(NativeMethods.NIM_MODIFY, data); + } + + private static void OnIsBlinkChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var ctl = (NotifyIcon)d; if (ctl.Visibility != Visibility.Visible) return; diff --git a/src/Shared/HandyControl_Shared/Data/Enum/ToolTipIcon.cs b/src/Shared/HandyControl_Shared/Data/Enum/ToolTipIcon.cs new file mode 100644 index 00000000..19acf612 --- /dev/null +++ b/src/Shared/HandyControl_Shared/Data/Enum/ToolTipIcon.cs @@ -0,0 +1,25 @@ +namespace HandyControl.Data +{ + public enum ToolTipIcon + { + /// + /// No Icon. + /// + None = 0, + + /// + /// A Information Icon. + /// + Info = 1, + + /// + /// A Warning Icon. + /// + Warning = 2, + + /// + /// A Error Icon. + /// + Error = 3 + } +} From 1918f71189db0c926d9bebe87e71783e8e91053a Mon Sep 17 00:00:00 2001 From: Liu Zhenpeng <1040063186@qq.com> Date: Tue, 10 Sep 2019 17:47:57 +0800 Subject: [PATCH 2/4] add ShowBalloonTip2 --- src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs | 2 +- src/Shared/HandyControl_Shared/HandyControl_Shared.projitems | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs index 80da1670..bfac04d3 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs @@ -165,6 +165,7 @@ namespace HandyControl.Controls public static readonly DependencyProperty IsBlinkProperty = DependencyProperty.Register( "IsBlink", typeof(bool), typeof(NotifyIcon), new PropertyMetadata(ValueBoxes.FalseBox, OnIsBlinkChanged)); + public void ShowBalloonTip(string tipTitle, string tipText, ToolTipIcon tipIcon) { if (DesignerHelper.IsInDesignMode) return; @@ -174,7 +175,6 @@ namespace HandyControl.Controls hWnd = _messageWindowHandle, uID = _id, uFlags = NativeMethods.NIF_INFO, - dwInfoFlags = NativeMethods.NIF_TIP, szInfoTitle = tipTitle ?? string.Empty, szInfo = tipText ?? string.Empty, }; diff --git a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems index 6aa8a170..15255d3a 100644 --- a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems +++ b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems @@ -35,6 +35,7 @@ + From 12bdc1a7275afe31a27bd379ba6f438d2a92f626 Mon Sep 17 00:00:00 2001 From: Liu Zhenpeng <1040063186@qq.com> Date: Tue, 10 Sep 2019 17:49:49 +0800 Subject: [PATCH 3/4] add ShowBalloonTip3 --- src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs index bfac04d3..e93310ad 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/NotifyIcon.cs @@ -195,9 +195,9 @@ namespace HandyControl.Controls break; } UnsafeNativeMethods.Shell_NotifyIcon(NativeMethods.NIM_MODIFY, data); - } + } - private static void OnIsBlinkChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + private static void OnIsBlinkChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var ctl = (NotifyIcon)d; if (ctl.Visibility != Visibility.Visible) return; From a91d33b0787ff8c3e42b7f1dd590c55cb2be1389 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Tue, 10 Sep 2019 23:41:10 +0800 Subject: [PATCH 4/4] modified the branch --- .../Data/MessageToken.cs | 4 + .../Data/MessageToken.tt | 4 +- .../Controls/NotifyIconDemoCtl.xaml | 59 +++--- .../Controls/NotifyIconDemoViewModel.cs | 21 ++ .../Controls/Other/NotifyIcon.cs | 191 ++++++++++++------ .../{ToolTipIcon.cs => NotifyIconInfoType.cs} | 10 +- .../HandyControl_Shared.projitems | 2 +- .../Tools/Interop/NativeMethods.cs | 1 + 8 files changed, 201 insertions(+), 91 deletions(-) rename src/Shared/HandyControl_Shared/Data/Enum/{ToolTipIcon.cs => NotifyIconInfoType.cs} (76%) diff --git a/src/Shared/HandyControlDemo_Shared/Data/MessageToken.cs b/src/Shared/HandyControlDemo_Shared/Data/MessageToken.cs index 3ffee119..818d5fba 100644 --- a/src/Shared/HandyControlDemo_Shared/Data/MessageToken.cs +++ b/src/Shared/HandyControlDemo_Shared/Data/MessageToken.cs @@ -198,5 +198,9 @@ public static readonly string BlogsView = nameof(BlogsView); + public static readonly string NotifyIconDemo = nameof(NotifyIconDemo); + + public static readonly string NotifyIconContextDemo = nameof(NotifyIconContextDemo); + } } \ No newline at end of file diff --git a/src/Shared/HandyControlDemo_Shared/Data/MessageToken.tt b/src/Shared/HandyControlDemo_Shared/Data/MessageToken.tt index 2978eea6..01e20c31 100644 --- a/src/Shared/HandyControlDemo_Shared/Data/MessageToken.tt +++ b/src/Shared/HandyControlDemo_Shared/Data/MessageToken.tt @@ -110,7 +110,9 @@ var messageList = new List "MainWindow", "OverView", "ProjectsView", - "BlogsView" + "BlogsView", + "NotifyIconDemo", + "NotifyIconContextDemo" }; #> namespace HandyControlDemo.Data diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/NotifyIconDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/NotifyIconDemoCtl.xaml index 98d1ac7c..4149ef39 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/NotifyIconDemoCtl.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/NotifyIconDemoCtl.xaml @@ -5,35 +5,42 @@ xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:command="http://www.galasoft.ch/mvvmlight" + xmlns:data="clr-namespace:HandyControlDemo.Data" DataContext="{Binding NotifyIconDemo,Source={StaticResource Locator}}" Background="{DynamicResource RegionBrush}"> - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + +