From cbb0bd0fc1e01067ab2e69fe8733d179b27a7300 Mon Sep 17 00:00:00 2001
From: NaBian <836904362@qq.com>
Date: Sat, 2 Mar 2019 14:38:13 +0800
Subject: [PATCH] init pr add-notifyicon
---
HandyControl/Controls/Other/NotifyIcon.cs | 31 ++++++++++++++++++
HandyControl/HandyControl.csproj | 1 +
HandyControl/Tools/Helper/ExternDllHelper.cs | 29 +++++++++++++++-
HandyControlDemo/Data/MessageToken.cs | 2 ++
HandyControlDemo/Data/MessageToken.tt | 3 +-
HandyControlDemo/HandyControlDemo.csproj | 8 +++++
.../Properties/Langs/Lang.Designer.cs | 11 ++++++-
.../Properties/Langs/Lang.en.resx | 3 ++
HandyControlDemo/Properties/Langs/Lang.resx | 3 ++
.../LeftMainContent/NotificationHub_16x.png | Bin 0 -> 335 bytes
.../Controls/ChatBubbleDemoCtl.xaml | 5 +--
.../Controls/NotifyIconDemoCtl.xaml | 8 +++++
.../Controls/NotifyIconDemoCtl.xaml.cs | 10 ++++++
.../UserControl/Main/LeftMainContent.xaml | 9 +++--
14 files changed, 116 insertions(+), 7 deletions(-)
create mode 100644 HandyControl/Controls/Other/NotifyIcon.cs
create mode 100644 HandyControlDemo/Resources/Img/LeftMainContent/NotificationHub_16x.png
create mode 100644 HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml
create mode 100644 HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml.cs
diff --git a/HandyControl/Controls/Other/NotifyIcon.cs b/HandyControl/Controls/Other/NotifyIcon.cs
new file mode 100644
index 00000000..c792ac4f
--- /dev/null
+++ b/HandyControl/Controls/Other/NotifyIcon.cs
@@ -0,0 +1,31 @@
+using System.Windows;
+using System.Windows.Controls.Primitives;
+using System.Windows.Media;
+using HandyControl.Tools;
+
+namespace HandyControl.Controls
+{
+ public class NotifyIcon : FrameworkElement
+ {
+ private Popup _trayPopup;
+
+ private readonly object _syncObj = new object();
+
+ public static readonly DependencyProperty IconProperty = DependencyProperty.Register(
+ "Icon", typeof(ImageSource), typeof(NotifyIcon), new PropertyMetadata(default(ImageSource)));
+
+ public ImageSource Icon
+ {
+ get => (ImageSource) GetValue(IconProperty);
+ set => SetValue(IconProperty, value);
+ }
+
+ private void UpdateIcon(bool showIconInTray)
+ {
+ lock (_syncObj)
+ {
+ if (DesignerHelper.IsInDesignMode) return;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj
index efbf174e..9168fd2f 100644
--- a/HandyControl/HandyControl.csproj
+++ b/HandyControl/HandyControl.csproj
@@ -112,6 +112,7 @@
+
diff --git a/HandyControl/Tools/Helper/ExternDllHelper.cs b/HandyControl/Tools/Helper/ExternDllHelper.cs
index d79faab7..345abe7a 100644
--- a/HandyControl/Tools/Helper/ExternDllHelper.cs
+++ b/HandyControl/Tools/Helper/ExternDllHelper.cs
@@ -10,13 +10,40 @@ using System.Threading;
namespace HandyControl.Tools
{
+ [SuppressMessage("ReSharper", "InconsistentNaming")]
internal class ExternDllHelper
{
private const string Gdi32 = "gdi32.dll";
private const string User32 = "user32.dll";
- // ReSharper disable once InconsistentNaming
+ private const string Shell32 = "shell32.dll";
+
+ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
+ public class NOTIFYICONDATA
+ {
+ public int cbSize = Marshal.SizeOf(typeof(NOTIFYICONDATA));
+ public IntPtr hWnd;
+ public int uID;
+ public int uFlags;
+ public int uCallbackMessage;
+ public IntPtr hIcon;
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
+ public string szTip;
+ public int dwState = 0;
+ public int dwStateMask = 0;
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
+ public string szInfo;
+ public int uTimeoutOrVersion;
+ [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
+ public string szInfoTitle;
+ public int dwInfoFlags;
+ }
+
+ [DllImport(Shell32, CharSet = CharSet.Auto)]
+ [ResourceExposure(ResourceScope.None)]
+ public static extern int Shell_NotifyIcon(int message, NOTIFYICONDATA pnid);
+
public const int E_FAIL = unchecked((int) 0x80004005);
[StructLayout(LayoutKind.Sequential)]
diff --git a/HandyControlDemo/Data/MessageToken.cs b/HandyControlDemo/Data/MessageToken.cs
index e63c9770..85aa8546 100644
--- a/HandyControlDemo/Data/MessageToken.cs
+++ b/HandyControlDemo/Data/MessageToken.cs
@@ -84,6 +84,8 @@
public static readonly string GotoTopDemoCtl = nameof(GotoTopDemoCtl);
+ public static readonly string NotifyIconDemoCtl = nameof(NotifyIconDemoCtl);
+
public static readonly string ButtonDemoCtl = nameof(ButtonDemoCtl);
public static readonly string ToggleButtonDemoCtl = nameof(ToggleButtonDemoCtl);
diff --git a/HandyControlDemo/Data/MessageToken.tt b/HandyControlDemo/Data/MessageToken.tt
index 377d9b64..ffdba442 100644
--- a/HandyControlDemo/Data/MessageToken.tt
+++ b/HandyControlDemo/Data/MessageToken.tt
@@ -44,7 +44,8 @@ var controlList = new List
"ProgressButtonDemoCtl",
"TransferDemoCtl",
"ChatBubbleDemoCtl",
- "GotoTopDemoCtl"
+ "GotoTopDemoCtl",
+ "NotifyIconDemoCtl"
};
var styleList = new List
{
diff --git a/HandyControlDemo/HandyControlDemo.csproj b/HandyControlDemo/HandyControlDemo.csproj
index fb8411db..998e6cf8 100644
--- a/HandyControlDemo/HandyControlDemo.csproj
+++ b/HandyControlDemo/HandyControlDemo.csproj
@@ -178,6 +178,9 @@
GotoTopDemoCtl.xaml
+
+ NotifyIconDemoCtl.xaml
+
OutlineTextDemoCtl.xaml
@@ -495,6 +498,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
@@ -753,6 +760,7 @@
TextTemplatingFileGenerator
MessageToken.cs
+
diff --git a/HandyControlDemo/Properties/Langs/Lang.Designer.cs b/HandyControlDemo/Properties/Langs/Lang.Designer.cs
index 44d750f8..a031bfb0 100644
--- a/HandyControlDemo/Properties/Langs/Lang.Designer.cs
+++ b/HandyControlDemo/Properties/Langs/Lang.Designer.cs
@@ -47,7 +47,7 @@ namespace HandyControlDemo.Properties.Langs {
}
///
- /// 重写当前线程的 CurrentUICulture 属性
+ /// 使用此强类型资源类,为所有资源查找
/// 重写当前线程的 CurrentUICulture 属性。
///
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
@@ -645,6 +645,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
+ ///
+ /// 查找类似 托盘图标 的本地化字符串。
+ ///
+ public static string NotifyIcon {
+ get {
+ return ResourceManager.GetString("NotifyIcon", resourceCulture);
+ }
+ }
+
///
/// 查找类似 数值选择控件 的本地化字符串。
///
diff --git a/HandyControlDemo/Properties/Langs/Lang.en.resx b/HandyControlDemo/Properties/Langs/Lang.en.resx
index 3f57a795..ff6aa4cf 100644
--- a/HandyControlDemo/Properties/Langs/Lang.en.resx
+++ b/HandyControlDemo/Properties/Langs/Lang.en.resx
@@ -501,4 +501,7 @@
GotoTop
+
+ NotifyIcon
+
\ No newline at end of file
diff --git a/HandyControlDemo/Properties/Langs/Lang.resx b/HandyControlDemo/Properties/Langs/Lang.resx
index 32ab263a..00755530 100644
--- a/HandyControlDemo/Properties/Langs/Lang.resx
+++ b/HandyControlDemo/Properties/Langs/Lang.resx
@@ -501,4 +501,7 @@
回到顶部
+
+ 托盘图标
+
\ No newline at end of file
diff --git a/HandyControlDemo/Resources/Img/LeftMainContent/NotificationHub_16x.png b/HandyControlDemo/Resources/Img/LeftMainContent/NotificationHub_16x.png
new file mode 100644
index 0000000000000000000000000000000000000000..49c9764453d18d9b84562dbe254b7a6f356ca531
GIT binary patch
literal 335
zcmV-V0kHmwP)u
z_|zmqW=D6y_kFA$SIF`VX`1fc1?)ny*7LlU-LRH(-U|5z_F!Ow`N#oHq>q7@g
hE(rvGmSruV;2%Mrbk^x1KJNek002ovPDHLkV1j%{jmiK3
literal 0
HcmV?d00001
diff --git a/HandyControlDemo/UserControl/Controls/ChatBubbleDemoCtl.xaml b/HandyControlDemo/UserControl/Controls/ChatBubbleDemoCtl.xaml
index b9b99343..285330c6 100644
--- a/HandyControlDemo/UserControl/Controls/ChatBubbleDemoCtl.xaml
+++ b/HandyControlDemo/UserControl/Controls/ChatBubbleDemoCtl.xaml
@@ -2,8 +2,9 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:userControl="clr-namespace:HandyControlDemo.UserControl"
+ xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
Background="{DynamicResource RegionBrush}">
-
+
@@ -16,5 +17,5 @@
-
+
diff --git a/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml b/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml
new file mode 100644
index 00000000..dc1085aa
--- /dev/null
+++ b/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml.cs b/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml.cs
new file mode 100644
index 00000000..93c2bd58
--- /dev/null
+++ b/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml.cs
@@ -0,0 +1,10 @@
+namespace HandyControlDemo.UserControl
+{
+ public partial class NotifyIconDemoCtl
+ {
+ public NotifyIconDemoCtl()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/HandyControlDemo/UserControl/Main/LeftMainContent.xaml b/HandyControlDemo/UserControl/Main/LeftMainContent.xaml
index 9828b9ef..07b35890 100644
--- a/HandyControlDemo/UserControl/Main/LeftMainContent.xaml
+++ b/HandyControlDemo/UserControl/Main/LeftMainContent.xaml
@@ -203,6 +203,11 @@
+
+
+
+
+
@@ -303,7 +308,7 @@
-
+
@@ -378,7 +383,7 @@
-
+