diff --git a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
index 8f0d5303..fae77e78 100644
--- a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
+++ b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
@@ -6,7 +6,7 @@
c4694269-c9b8-45d5-87f8-d0088c532510
- HandyControlDemo_Shared
+ HandyControlDemo
diff --git a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
index f6f529e4..b6160619 100644
--- a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
+++ b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
@@ -6,7 +6,7 @@
aac11083-faca-405d-9197-5c1212d65656
- HandyControl_Shared
+ HandyControl
@@ -271,6 +271,7 @@
+
diff --git a/src/Shared/HandyControl_Shared/Tools/Hook/ClipboardHook.cs b/src/Shared/HandyControl_Shared/Tools/Hook/ClipboardHook.cs
new file mode 100644
index 00000000..2c4de7fe
--- /dev/null
+++ b/src/Shared/HandyControl_Shared/Tools/Hook/ClipboardHook.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Windows;
+using System.Windows.Interop;
+using HandyControl.Tools.Interop;
+
+namespace HandyControl.Tools
+{
+ public class ClipboardHook
+ {
+ private static HwndSource HWndSource;
+
+ private static IntPtr HookId = IntPtr.Zero;
+
+ public static event Action ContentChanged;
+
+ public static void Start()
+ {
+ if (HookId != IntPtr.Zero)
+ {
+ Stop();
+ }
+
+ HookId = new WindowInteropHelper(new Window()).EnsureHandle();
+ HWndSource = HwndSource.FromHwnd(HookId);
+ if (HWndSource != null)
+ {
+ HWndSource.AddHook(WinProc);
+ NativeMethods.AddClipboardFormatListener(HookId);
+ }
+ }
+
+ public static void Stop() => NativeMethods.RemoveClipboardFormatListener(HookId);
+
+ private static IntPtr WinProc(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
+ {
+ if (msg == NativeMethods.WM_CLIPBOARDUPDATE)
+ {
+ ContentChanged?.Invoke();
+ }
+ return IntPtr.Zero;
+ }
+ }
+}
diff --git a/src/Shared/HandyControl_Shared/Tools/Interop/NativeMethods.cs b/src/Shared/HandyControl_Shared/Tools/Interop/NativeMethods.cs
index 59c7dec7..b010ff9d 100644
--- a/src/Shared/HandyControl_Shared/Tools/Interop/NativeMethods.cs
+++ b/src/Shared/HandyControl_Shared/Tools/Interop/NativeMethods.cs
@@ -46,6 +46,7 @@ namespace HandyControl.Tools.Interop
WM_MBUTTONDOWN = 0x0207,
WM_MBUTTONUP = 0x0208,
WM_MBUTTONDBLCLK = 0x0209,
+ WM_CLIPBOARDUPDATE = 0x031D,
WM_USER = 0x0400,
TB_GETBUTTON = WM_USER + 23,
TB_BUTTONCOUNT = WM_USER + 24,
@@ -223,5 +224,13 @@ namespace HandyControl.Tools.Interop
[DllImport(ExternDll.User32)]
public static extern IntPtr GetDesktopWindow();
+
+ [DllImport(ExternDll.User32, SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool AddClipboardFormatListener(IntPtr hwnd);
+
+ [DllImport(ExternDll.User32, SetLastError = true)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ public static extern bool RemoveClipboardFormatListener(IntPtr hwnd);
}
}
\ No newline at end of file