dev 19-3-27
This commit is contained in:
1 parent
93c351a308
commit
2cd021d34c
3 files changed
+196
-12
No files matched your search
@@ -3,6 +3,7 @@ using System.Windows;
|
|||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Controls.Primitives;
|
using System.Windows.Controls.Primitives;
|
||||||
using System.Windows.Data;
|
using System.Windows.Data;
|
||||||
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using HandyControl.Tools;
|
using HandyControl.Tools;
|
||||||
using HandyControl.Tools.Interop;
|
using HandyControl.Tools.Interop;
|
||||||
@@ -41,6 +42,10 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
private ToolTip _toolTip;
|
private ToolTip _toolTip;
|
||||||
|
|
||||||
|
private Popup _contextMenu;
|
||||||
|
|
||||||
|
private bool _doubleClick;
|
||||||
|
|
||||||
public NotifyIcon()
|
public NotifyIcon()
|
||||||
{
|
{
|
||||||
_id = ++NextId;
|
_id = ++NextId;
|
||||||
@@ -56,14 +61,14 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
var ctl = (NotifyIcon) d;
|
var ctl = (NotifyIcon)d;
|
||||||
ctl._icon = (ImageSource) e.NewValue;
|
ctl._icon = (ImageSource)e.NewValue;
|
||||||
ctl.OnIconChanged();
|
ctl.OnIconChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageSource Icon
|
public ImageSource Icon
|
||||||
{
|
{
|
||||||
get => (ImageSource) GetValue(IconProperty);
|
get => (ImageSource)GetValue(IconProperty);
|
||||||
set => SetValue(IconProperty, value);
|
set => SetValue(IconProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,26 +169,195 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
private IntPtr Callback(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
|
private IntPtr Callback(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam)
|
||||||
{
|
{
|
||||||
if (msg == WmTaskbarcreated)
|
if (IsLoaded)
|
||||||
{
|
{
|
||||||
UpdateIcon(true);
|
if (msg == WmTaskbarcreated)
|
||||||
|
{
|
||||||
|
UpdateIcon(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//switch (lparam.ToInt32())
|
||||||
|
//{
|
||||||
|
// 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);
|
||||||
|
// break;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
var point = new POINT();
|
||||||
|
UnsafeNativeMethods.GetCursorPos(point);
|
||||||
|
ShowToolTip(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
return UnsafeNativeMethods.DefWindowProc(hWnd, msg, wparam, lparam);
|
return UnsafeNativeMethods.DefWindowProc(hWnd, msg, wparam, lparam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void WmMouseDown(MouseButton button, int clicks)
|
||||||
|
{
|
||||||
|
if (clicks == 2)
|
||||||
|
{
|
||||||
|
OnMouseDoubleClick(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, button)
|
||||||
|
{
|
||||||
|
Source = this,
|
||||||
|
RoutedEvent = MouseDoubleClickEvent
|
||||||
|
});
|
||||||
|
_doubleClick = true;
|
||||||
|
}
|
||||||
|
OnMouseDown(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, button)
|
||||||
|
{
|
||||||
|
Source = this,
|
||||||
|
RoutedEvent = MouseDownEvent
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WmMouseUp(MouseButton button)
|
||||||
|
{
|
||||||
|
OnMouseUp(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, button)
|
||||||
|
{
|
||||||
|
Source = this,
|
||||||
|
RoutedEvent = MouseUpEvent
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!_doubleClick)
|
||||||
|
{
|
||||||
|
OnClick(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, button)
|
||||||
|
{
|
||||||
|
Source = this,
|
||||||
|
RoutedEvent = ClickEvent
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_doubleClick = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WmMouseMove()
|
||||||
|
{
|
||||||
|
OnMouseMove(new MouseEventArgs(Mouse.PrimaryDevice, Environment.TickCount)
|
||||||
|
{
|
||||||
|
RoutedEvent = MouseMoveEvent,
|
||||||
|
Source = this,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowContextMenu()
|
||||||
|
{
|
||||||
|
if (ContextMenu != null) ContextMenu.IsOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ShowToolTip(POINT point)
|
||||||
|
{
|
||||||
|
if (_toolTip != null)
|
||||||
|
{
|
||||||
|
_toolTip.HorizontalOffset = point.x;
|
||||||
|
_toolTip.VerticalOffset = point.x;
|
||||||
|
_toolTip.IsOpen = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void CreateToolTip()
|
private void CreateToolTip()
|
||||||
{
|
{
|
||||||
_toolTip = new ToolTip
|
_toolTip = new ToolTip
|
||||||
{
|
{
|
||||||
Placement = PlacementMode.Mouse,
|
Placement = PlacementMode.AbsolutePoint,
|
||||||
HasDropShadow = false,
|
HasDropShadow = false,
|
||||||
BorderThickness = new Thickness(0),
|
BorderThickness = new Thickness(0),
|
||||||
Background = Brushes.Transparent
|
Background = Brushes.Transparent
|
||||||
};
|
};
|
||||||
|
|
||||||
_toolTip.SetBinding(ContentControl.ContentProperty, new Binding(ToolTipProperty.Name) {Source = this});
|
_toolTip.SetBinding(ContentControl.ContentProperty, new Binding(ToolTipProperty.Name) { Source = this });
|
||||||
_toolTip.SetBinding(DataContextProperty, new Binding(DataContextProperty.Name) { Source = this });
|
_toolTip.SetBinding(DataContextProperty, new Binding(DataContextProperty.Name) { Source = this });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static readonly RoutedEvent ClickEvent =
|
||||||
|
EventManager.RegisterRoutedEvent("Click", RoutingStrategy.Bubble,
|
||||||
|
typeof(RoutedEventHandler), typeof(NotifyIcon));
|
||||||
|
|
||||||
|
public event RoutedEventHandler Click
|
||||||
|
{
|
||||||
|
add => AddHandler(ClickEvent, value);
|
||||||
|
remove => RemoveHandler(ClickEvent, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly RoutedEvent MouseDoubleClickEvent =
|
||||||
|
EventManager.RegisterRoutedEvent("MouseDoubleClick", RoutingStrategy.Bubble,
|
||||||
|
typeof(RoutedEventHandler), typeof(NotifyIcon));
|
||||||
|
|
||||||
|
public event RoutedEventHandler MouseDoubleClick
|
||||||
|
{
|
||||||
|
add => AddHandler(MouseDoubleClickEvent, value);
|
||||||
|
remove => RemoveHandler(MouseDoubleClickEvent, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly RoutedEvent BalloonTipShownEvent =
|
||||||
|
EventManager.RegisterRoutedEvent("BalloonTipShown", RoutingStrategy.Bubble,
|
||||||
|
typeof(RoutedEventHandler), typeof(NotifyIcon));
|
||||||
|
|
||||||
|
public event RoutedEventHandler BalloonTipShown
|
||||||
|
{
|
||||||
|
add => AddHandler(BalloonTipShownEvent, value);
|
||||||
|
remove => RemoveHandler(BalloonTipShownEvent, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly RoutedEvent BalloonTipClosedEvent =
|
||||||
|
EventManager.RegisterRoutedEvent("BalloonTipClosed", RoutingStrategy.Bubble,
|
||||||
|
typeof(RoutedEventHandler), typeof(NotifyIcon));
|
||||||
|
|
||||||
|
public event RoutedEventHandler BalloonTipClosed
|
||||||
|
{
|
||||||
|
add => AddHandler(BalloonTipClosedEvent, value);
|
||||||
|
remove => RemoveHandler(BalloonTipClosedEvent, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnClick(MouseButtonEventArgs e) => RaiseEvent(e);
|
||||||
|
|
||||||
|
protected virtual void OnDoubleClick(MouseButtonEventArgs e) => RaiseEvent(e);
|
||||||
|
|
||||||
|
protected virtual void OnMouseDoubleClick(MouseButtonEventArgs e) => RaiseEvent(e);
|
||||||
|
|
||||||
|
protected override void OnMouseDown(MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseDown(e);
|
||||||
|
RaiseEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseUp(MouseButtonEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseUp(e);
|
||||||
|
RaiseEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnMouseMove(MouseEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnMouseMove(e);
|
||||||
|
RaiseEvent(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,22 +13,32 @@ namespace HandyControl.Tools.Interop
|
|||||||
{
|
{
|
||||||
public const int
|
public const int
|
||||||
WS_CHILD = 0x40000000,
|
WS_CHILD = 0x40000000,
|
||||||
WM_USER = 0x0400,
|
|
||||||
BITSPIXEL = 12,
|
BITSPIXEL = 12,
|
||||||
PLANES = 14,
|
PLANES = 14,
|
||||||
BI_RGB = 0,
|
BI_RGB = 0,
|
||||||
DIB_RGB_COLORS = 0,
|
DIB_RGB_COLORS = 0,
|
||||||
NIF_MESSAGE = 0x00000001,
|
NIF_MESSAGE = 0x00000001,
|
||||||
NIF_INFO = 0x00000010,
|
|
||||||
NIF_ICON = 0x00000002,
|
NIF_ICON = 0x00000002,
|
||||||
NIF_TIP = 0x00000004,
|
NIF_TIP = 0x00000004,
|
||||||
|
NIF_INFO = 0x00000010,
|
||||||
NIM_ADD = 0x00000000,
|
NIM_ADD = 0x00000000,
|
||||||
NIM_DELETE = 0x00000002,
|
|
||||||
NIM_MODIFY = 0x00000001,
|
NIM_MODIFY = 0x00000001,
|
||||||
|
NIM_DELETE = 0x00000002,
|
||||||
NIIF_NONE = 0x00000000,
|
NIIF_NONE = 0x00000000,
|
||||||
NIIF_INFO = 0x00000001,
|
NIIF_INFO = 0x00000001,
|
||||||
NIIF_WARNING = 0x00000002,
|
NIIF_WARNING = 0x00000002,
|
||||||
NIIF_ERROR = 0x00000003;
|
NIIF_ERROR = 0x00000003,
|
||||||
|
WM_MOUSEMOVE = 0x0200,
|
||||||
|
WM_LBUTTONDOWN = 0x0201,
|
||||||
|
WM_LBUTTONUP = 0x0202,
|
||||||
|
WM_LBUTTONDBLCLK = 0x0203,
|
||||||
|
WM_RBUTTONDOWN = 0x0204,
|
||||||
|
WM_RBUTTONUP = 0x0205,
|
||||||
|
WM_RBUTTONDBLCLK = 0x0206,
|
||||||
|
WM_MBUTTONDOWN = 0x0207,
|
||||||
|
WM_MBUTTONUP = 0x0208,
|
||||||
|
WM_MBUTTONDBLCLK = 0x0209,
|
||||||
|
WM_USER = 0x0400;
|
||||||
|
|
||||||
[DllImport(ExternDll.User32, CharSet = CharSet.Auto)]
|
[DllImport(ExternDll.User32, CharSet = CharSet.Auto)]
|
||||||
[ResourceExposure(ResourceScope.None)]
|
[ResourceExposure(ResourceScope.None)]
|
||||||
|
|||||||
@@ -4,6 +4,6 @@
|
|||||||
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
|
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
|
||||||
Background="{DynamicResource RegionBrush}">
|
Background="{DynamicResource RegionBrush}">
|
||||||
<Grid>
|
<Grid>
|
||||||
<controls:NotifyIcon Text="123" BalloonTipText="123" BalloonTipTitle="123"/>
|
<controls:NotifyIcon ToolTip="123"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
Reference in new issue
Block a user