How to get a clipboard paste notification and provide my own data?

Uwe Keim picture Uwe Keim · Feb 19, 2010 · Viewed 9.7k times · Source

For a small utility I am writing (.NET, C#), I want to monitor clipboard copy operations and clipboard paste operations.

My idea is to provide my own data when pasting into an arbitrary application.

The monitoring of a copy operation can be easily done by using a clipboard viewer.

Something that seems much more advanced to me is to write a "clipboard paste provider":

  • Answer to "what formats are available" queries of applications.
  • Supply data to application paste operations.

I found this posting and this posting, but none of them seems to really help me.

What I guess is that I somehow have to mimic/hijack the current clipboard.

Question:

Is it possible to "wrap" the clipboard in terms of paste operations and provide my own kind of "clipboard proxy"?

Answer

t0mm13b picture t0mm13b · Feb 19, 2010

You need to hook in the clipboard hook by using a windows hook. A windows hook is a way of intercepting global events happening and providing your own hook procedure to replace or intercept the message. Have a look here on CodeProject that explains how to hook. Here's a clipboard helper that listens for the copy/paste functionality. Here's a Clipboard spy that just does that. Here's another article that implements a Clipboard hook.