Created
April 30, 2016 16:11
-
-
Save idiotandrobot/c22549ba57fd68240c32d53a82121533 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DllImport("user32.dll", SetLastError = true)] | |
[return: MarshalAs(UnmanagedType.Bool)] | |
static extern bool AddClipboardFormatListener(IntPtr hwnd); | |
[DllImport("user32.dll", SetLastError = true)] | |
[return: MarshalAs(UnmanagedType.Bool)] | |
static extern bool RemoveClipboardFormatListener(IntPtr hwnd); | |
private const int WM_CLIPBOARDUPDATE = 0x031D; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override void WndProc(ref Message m) | |
{ | |
base.WndProc(ref m); | |
if (m.Msg == WM_CLIPBOARDUPDATE) | |
{ | |
var data = Clipboard.GetDataObject(); | |
if (data.GetDataPresent(DataFormats.Text)) | |
{ | |
string text = (string)data.GetData(DataFormats.Text); | |
} | |
else if (data.GetDataPresent(DataFormats.Bitmap)) | |
{ | |
Bitmap image = (Bitmap)data.GetData(DataFormats.Bitmap); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AddClipboardFormatListener(this.Handle); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void Form_FormClosing(object sender, FormClosingEventArgs e) | |
{ | |
RemoveClipboardFormatListener(this.Handle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment