diff --git a/HandyControl/Controls/Other/NotifyIcon.cs b/HandyControl/Controls/Other/NotifyIcon.cs
index 64c2e802..c916b913 100644
--- a/HandyControl/Controls/Other/NotifyIcon.cs
+++ b/HandyControl/Controls/Other/NotifyIcon.cs
@@ -50,6 +50,8 @@ namespace HandyControl.Controls
private bool _isTransparent;
+ private bool _isDisposed;
+
static NotifyIcon()
{
VisibilityProperty.OverrideMetadata(typeof(NotifyIcon), new PropertyMetadata(Visibility.Visible, OnVisibilityChanged));
@@ -238,7 +240,6 @@ namespace HandyControl.Controls
uCallbackMessage = WmTrayMouseMessage,
uFlags = NativeMethods.NIF_MESSAGE | NativeMethods.NIF_ICON | NativeMethods.NIF_TIP,
hWnd = _messageWindowHandle,
- uTimeoutOrVersion = 10,
uID = _id,
dwInfoFlags = NativeMethods.NIF_TIP,
hIcon = isTransparent ? IntPtr.Zero : _currentSmallIconHandle.CriticalGetHandle(),
@@ -284,7 +285,8 @@ namespace HandyControl.Controls
UnsafeNativeMethods.RegisterClass(wndclass);
_wmTaskbarCreated = NativeMethods.RegisterWindowMessage("TaskbarCreated");
- _messageWindowHandle = UnsafeNativeMethods.CreateWindowEx(0, _windowClassName, "", 0, 0, 0, 1, 1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
+ _messageWindowHandle = UnsafeNativeMethods.CreateWindowEx(0, _windowClassName, "", 0, 0, 0, 1, 1,
+ IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
}
private IntPtr Callback(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
@@ -302,30 +304,9 @@ namespace HandyControl.Controls
case NativeMethods.WM_LBUTTONDBLCLK:
WmMouseDown(MouseButton.Left, 2);
break;
- case NativeMethods.WM_LBUTTONDOWN:
- WmMouseDown(MouseButton.Left, 1);
- break;
case NativeMethods.WM_LBUTTONUP:
WmMouseUp(MouseButton.Left);
break;
- case NativeMethods.WM_MBUTTONDBLCLK:
- WmMouseDown(MouseButton.Middle, 2);
- break;
- case NativeMethods.WM_MBUTTONDOWN:
- WmMouseDown(MouseButton.Middle, 1);
- break;
- case NativeMethods.WM_MBUTTONUP:
- WmMouseUp(MouseButton.Middle);
- break;
- case NativeMethods.WM_MOUSEMOVE:
- WmMouseMove();
- break;
- case NativeMethods.WM_RBUTTONDBLCLK:
- WmMouseDown(MouseButton.Right, 2);
- break;
- case NativeMethods.WM_RBUTTONDOWN:
- WmMouseDown(MouseButton.Right, 1);
- break;
case NativeMethods.WM_RBUTTONUP:
ShowContextMenu();
WmMouseUp(MouseButton.Right);
@@ -347,20 +328,11 @@ namespace HandyControl.Controls
});
_doubleClick = true;
}
- RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, button)
- {
- RoutedEvent = MouseDownEvent
- });
}
private void WmMouseUp(MouseButton button)
{
- RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, button)
- {
- RoutedEvent = MouseUpEvent
- });
-
- if (!_doubleClick)
+ if (!_doubleClick && button == MouseButton.Left)
{
RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, button)
{
@@ -370,14 +342,6 @@ namespace HandyControl.Controls
_doubleClick = false;
}
- private void WmMouseMove()
- {
- RaiseEvent(new MouseEventArgs(Mouse.PrimaryDevice, Environment.TickCount)
- {
- RoutedEvent = MouseMoveEvent
- });
- }
-
private void ShowContextMenu()
{
var point = new POINT();
@@ -449,6 +413,7 @@ namespace HandyControl.Controls
private void Dispose(bool disposing)
{
+ if (_isDisposed) return;
if (disposing)
{
if (_dispatcherTimer != null && IsBlink)
@@ -461,6 +426,8 @@ namespace HandyControl.Controls
_currentLargeIconHandle?.Dispose();
_currentSmallIconHandle?.Dispose();
}
+
+ _isDisposed = true;
}
public void Dispose()
@@ -468,5 +435,17 @@ namespace HandyControl.Controls
Dispose(true);
GC.SuppressFinalize(this);
}
+
+ public void CloseContextControl()
+ {
+ if (_contextContent != null)
+ {
+ _contextContent.IsOpen = false;
+ }
+ else if (ContextMenu != null)
+ {
+ ContextMenu.IsOpen = false;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/HandyControl/Data/Enum/ToolTipIcon.cs b/HandyControl/Data/Enum/ToolTipIcon.cs
deleted file mode 100644
index d14beaed..00000000
--- a/HandyControl/Data/Enum/ToolTipIcon.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace HandyControl.Data
-{
- public enum ToolTipIcon
- {
- None,
- Info,
- Warning,
- Error
- }
-}
\ No newline at end of file
diff --git a/HandyControl/Data/Icon.cs b/HandyControl/Data/Icon.cs
deleted file mode 100644
index d962da56..00000000
--- a/HandyControl/Data/Icon.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using HandyControl.Tools.Interop;
-using System;
-using System.Diagnostics.CodeAnalysis;
-
-namespace HandyControl.Data
-{
- public sealed class Icon : IDisposable
- {
- private IntPtr _handle;
-
- ~Icon()
- {
- Dispose(false);
- }
-
- internal Icon(IntPtr handle)
- {
- if (handle == IntPtr.Zero)
- {
- throw new ArgumentException("InvalidGDIHandle", typeof(Icon).Name);
- }
- _handle = handle;
- }
-
- [SuppressMessage("ReSharper", "UnusedParameter.Local")]
- private void Dispose(bool disposing)
- {
- if (_handle != IntPtr.Zero)
- {
- UnsafeNativeMethods.DestroyIcon(_handle);
- _handle = IntPtr.Zero;
- }
- }
-
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- }
-}
\ No newline at end of file
diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj
index 8a67d368..8ec96797 100644
--- a/HandyControl/HandyControl.csproj
+++ b/HandyControl/HandyControl.csproj
@@ -172,13 +172,11 @@
-
-
diff --git a/HandyControl/Interactivity/PushMainWindow2TopCommand.cs b/HandyControl/Interactivity/PushMainWindow2TopCommand.cs
index 3bc1ca18..65e96979 100644
--- a/HandyControl/Interactivity/PushMainWindow2TopCommand.cs
+++ b/HandyControl/Interactivity/PushMainWindow2TopCommand.cs
@@ -12,7 +12,7 @@ namespace HandyControl.Interactivity
public void Execute(object parameter)
{
- if (Application.Current.MainWindow != null)
+ if (Application.Current.MainWindow != null && Application.Current.MainWindow.Visibility != Visibility.Visible)
{
Application.Current.MainWindow.Show();
var hwndSource = (HwndSource)PresentationSource.FromDependencyObject(Application.Current.MainWindow);
diff --git a/HandyControl/Tools/Helper/SecurityHelper.cs b/HandyControl/Tools/Helper/SecurityHelper.cs
index af582881..10c17ec4 100644
--- a/HandyControl/Tools/Helper/SecurityHelper.cs
+++ b/HandyControl/Tools/Helper/SecurityHelper.cs
@@ -1,8 +1,10 @@
-using System.Security;
+using System.Diagnostics.CodeAnalysis;
+using System.Security;
using System.Security.Permissions;
namespace HandyControl.Tools
{
+ [SuppressMessage("ReSharper", "InconsistentNaming")]
internal class SecurityHelper
{
private static UIPermission _allWindowsUIPermission;
diff --git a/HandyControl/Tools/Interop/HandleCollector.cs b/HandyControl/Tools/Interop/HandleCollector.cs
index b53f3c96..e0500e0f 100644
--- a/HandyControl/Tools/Interop/HandleCollector.cs
+++ b/HandyControl/Tools/Interop/HandleCollector.cs
@@ -105,11 +105,11 @@ namespace HandyControl.Tools.Interop
if (_handleCount > _threshHold)
{
- _threshHold = _handleCount + ((_handleCount * _deltaPercent) / 100);
+ _threshHold = _handleCount + _handleCount * _deltaPercent / 100;
return true;
}
- var oldThreshHold = (100 * _threshHold) / (100 + _deltaPercent);
+ var oldThreshHold = 100 * _threshHold / (100 + _deltaPercent);
if (oldThreshHold >= _initialThreshHold && _handleCount < (int)(oldThreshHold * .9F))
{
_threshHold = oldThreshHold;
diff --git a/HandyControl/Tools/Interop/ICONINFO.cs b/HandyControl/Tools/Interop/ICONINFO.cs
index 564e8df9..659c98e6 100644
--- a/HandyControl/Tools/Interop/ICONINFO.cs
+++ b/HandyControl/Tools/Interop/ICONINFO.cs
@@ -1,8 +1,10 @@
-using System.Runtime.InteropServices;
+using System.Diagnostics.CodeAnalysis;
+using System.Runtime.InteropServices;
namespace HandyControl.Tools.Interop
{
[StructLayout(LayoutKind.Sequential)]
+ [SuppressMessage("ReSharper", "InconsistentNaming")]
internal class ICONINFO
{
public bool fIcon = false;
diff --git a/HandyControl/Tools/Interop/NOTIFYICONDATA.cs b/HandyControl/Tools/Interop/NOTIFYICONDATA.cs
index 6794cbb0..c57d604a 100644
--- a/HandyControl/Tools/Interop/NOTIFYICONDATA.cs
+++ b/HandyControl/Tools/Interop/NOTIFYICONDATA.cs
@@ -15,14 +15,14 @@ namespace HandyControl.Tools.Interop
public int uCallbackMessage;
public IntPtr hIcon;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
- public string szTip;
- public int dwState = 0;
- public int dwStateMask = 0;
+ public string szTip = string.Empty;
+ public int dwState = 0x01;
+ public int dwStateMask = 0x01;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
- public string szInfo;
+ public string szInfo = string.Empty;
public int uTimeoutOrVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
- public string szInfoTitle;
+ public string szInfoTitle = string.Empty;
public int dwInfoFlags;
}
}
\ No newline at end of file
diff --git a/HandyControl/Tools/Interop/UnsafeNativeMethods.cs b/HandyControl/Tools/Interop/UnsafeNativeMethods.cs
index 76ac1fe6..f4ff08dd 100644
--- a/HandyControl/Tools/Interop/UnsafeNativeMethods.cs
+++ b/HandyControl/Tools/Interop/UnsafeNativeMethods.cs
@@ -165,7 +165,9 @@ namespace HandyControl.Tools.Interop
IntPtr hInstance,
IntPtr lpParam);
- [DllImport(ExternDll.User32, CharSet = CharSet.Auto, SetLastError = true)]
+ [SecurityCritical]
+ [SuppressUnmanagedCodeSecurity]
+ [DllImport(ExternDll.User32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
public static extern short RegisterClass(WNDCLASS wc);
[DllImport(ExternDll.User32, CharSet = CharSet.Auto)]
diff --git a/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml b/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml
index 15ab993d..bcb6864b 100644
--- a/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml
+++ b/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml
@@ -4,53 +4,73 @@
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
xmlns:interactivity="clr-namespace:HandyControl.Interactivity;assembly=HandyControl"
+ xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
+ xmlns:command="http://www.galasoft.ch/mvvmlight"
DataContext="{Binding NotifyIconDemo,Source={StaticResource Locator}}"
Background="{DynamicResource RegionBrush}">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml.cs b/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml.cs
index 93c2bd58..4efd472c 100644
--- a/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml.cs
+++ b/HandyControlDemo/UserControl/Controls/NotifyIconDemoCtl.xaml.cs
@@ -1,4 +1,6 @@
-namespace HandyControlDemo.UserControl
+using System.Windows;
+
+namespace HandyControlDemo.UserControl
{
public partial class NotifyIconDemoCtl
{
@@ -6,5 +8,7 @@
{
InitializeComponent();
}
+
+ private void ButtonPush_OnClick(object sender, RoutedEventArgs e) => NotifyIconContextContent.CloseContextControl();
}
}
diff --git a/HandyControlDemo/ViewModel/Controls/NotifyIconDemoViewModel.cs b/HandyControlDemo/ViewModel/Controls/NotifyIconDemoViewModel.cs
index 2a40d6af..77456549 100644
--- a/HandyControlDemo/ViewModel/Controls/NotifyIconDemoViewModel.cs
+++ b/HandyControlDemo/ViewModel/Controls/NotifyIconDemoViewModel.cs
@@ -1,4 +1,7 @@
-using GalaSoft.MvvmLight;
+using System;
+using GalaSoft.MvvmLight;
+using GalaSoft.MvvmLight.CommandWpf;
+using HandyControl.Controls;
using HandyControlDemo.Data;
namespace HandyControlDemo.ViewModel
@@ -44,5 +47,8 @@ namespace HandyControlDemo.ViewModel
get => _contextContentIsBlink;
set => Set(ref _contextContentIsBlink, value);
}
+
+ public RelayCommand