Skip to content

Instantly share code, notes, and snippets.

@unarist
Created August 26, 2013 15:32
Show Gist options
  • Save unarist/6342758 to your computer and use it in GitHub Desktop.
Save unarist/6342758 to your computer and use it in GitHub Desktop.
クリップボードを監視してテキストボックスに追加していく感じの。
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
internal class MainForm : Form
{
[DllImport("user32.dll", SetLastError = true)]
private extern static void AddClipboardFormatListener(IntPtr hwnd);
[DllImport("user32.dll", SetLastError = true)]
private extern static void RemoveClipboardFormatListener(IntPtr hwnd);
private TextBox log;
public MainForm()
{
log = new TextBox
{
Dock = DockStyle.Fill,
Multiline = true
};
Controls.Add(log);
}
protected override void OnLoad(EventArgs e)
{
AddClipboardFormatListener(Handle);
base.OnLoad(e);
}
protected override void Dispose(bool disposing)
{
RemoveClipboardFormatListener(Handle);
base.Dispose(disposing);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x31D)
{
log.Text += Clipboard.GetText() + "\r\n";
m.Result = IntPtr.Zero;
}
else base.WndProc(ref m);
}
}
internal class Program
{
[STAThread]
private static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.Run(new MainForm());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment