1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| public partial class Form1 : Form { public const int WM_CLIPBOARDUPDATE = 0x031D; [DllImport("user32.dll", SetLastError = true)] public static extern bool AddClipboardFormatListener(IntPtr hWnd); [DllImport("user32.dll", SetLastError = true)] public static extern bool RemoveClipboardFormatListener(IntPtr hWnd);
public Form1() { InitializeComponent(); AddClipboardFormatListener(this.Handle); Message mes = new Message(); DefWndProc(ref mes); } protected override void DefWndProc(ref Message m) { if (m.Msg == WM_CLIPBOARDUPDATE) { if (Clipboard.ContainsText()) { Console.WriteLine(Clipboard.GetText()); } else if (Clipboard.ContainsImage()) { Console.WriteLine("图片"); } else {
Console.WriteLine("其他待处理的文件类型"); } } else { base.DefWndProc(ref m); } } }
|