mirror of
https://github.com/ZiuChen/ClipboardManager.git
synced 2025-12-24 19:49:35 +08:00
feat: 添加clipboard-event不同平台源代码
This commit is contained in:
44
public/node_modules/clipboard-event/platform/clipboard-event-handler-win32.cs
generated
vendored
Normal file
44
public/node_modules/clipboard-event/platform/clipboard-event-handler-win32.cs
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace clipboard_event_handler_win32 {
|
||||
internal static class NativeMethods {
|
||||
//Reference https://docs.microsoft.com/en-us/windows/desktop/dataxchg/wm-clipboardupdate
|
||||
public const int WM_CLIPBOARDUPDATE = 0x031D;
|
||||
//Reference https://www.pinvoke.net/default.aspx/Constants.HWND
|
||||
public static IntPtr HWND_MESSAGE = new IntPtr(-3);
|
||||
//Reference https://www.pinvoke.net/default.aspx/user32/AddClipboardFormatListener.html
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool AddClipboardFormatListener(IntPtr hwnd);
|
||||
//Reference https://www.pinvoke.net/default.aspx/user32.setparent
|
||||
[DllImport("user32.dll", SetLastError = true)]
|
||||
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
|
||||
}
|
||||
|
||||
public sealed class ClipboardNotification {
|
||||
private class NotificationForm : Form {
|
||||
public NotificationForm() {
|
||||
//Turn the child window into a message-only window (refer to Microsoft docs)
|
||||
NativeMethods.SetParent(Handle, NativeMethods.HWND_MESSAGE);
|
||||
//Place window in the system-maintained clipboard format listener list
|
||||
NativeMethods.AddClipboardFormatListener(Handle);
|
||||
}
|
||||
|
||||
protected override void WndProc(ref Message m) {
|
||||
//Listen for operating system messages
|
||||
if (m.Msg == NativeMethods.WM_CLIPBOARDUPDATE)
|
||||
{
|
||||
Console.WriteLine("CLIPBOARD_CHANGE");
|
||||
}
|
||||
//Called for any unhandled messages
|
||||
base.WndProc(ref m);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Main(string[] args) {
|
||||
Application.Run(new NotificationForm());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user