This is not easy. I can explain how to do it in native code and C++ and you can think how to inter-operate with you C# project using P/Invoke.
First of all, you can write some code for a windows function to participate in a clipboard viewer chain.
Look here:
http://msdn.microsoft.com/en-us/library/ms649016(v=vs.85).aspx#_win32_Example_of_a_Clipboard_Viewer[
^], pay attention for the section "Example of a Clipboard Viewer".
You can do it when you're writing full windows function. (Are you familiar with this part of native Windows programming? In not, you need to either learn about it or forget about the topic.) If this is not "your" windows class, you need to work with the instance of the windowed control. This is even more tricky.
You need to write a new windows function which can call some other windows function (chaining). Now, you need to extract existing windows function from the instance of your browser control using Windows API
GetWindowLong
using you
HWND
and the parameter
GWL_WNDPROC
. Your "new" windows function should use the extracted "old" windows function when processing all windows messages except those needed for Clipboard chain interception. You need to set you "new" windows function to the window participated in the chain using Windows API
SetWindowLong
, with your
HWND
,
index
parameter equals to
GWL_WNDPROC
and the address of your "new" windows function.
See:
http://msdn.microsoft.com/en-us/library/ms633584(v=vs.85).aspx[
^],
http://msdn.microsoft.com/en-us/library/ms633591(v=vs.85).aspx[
^].
Even when you do it all, you have limited opportunities.
Look here:
http://www.visualstudiodev.com/visual-studio-tools-for-office/intercept-wmcopy-message-in-excel-vsto-57106.shtml[
^]:
"The only clipboard hooking mechanism provided by the operating system is the clipboard viewer chain. You can see what is put on the clipboard, but you can't tell what applications are doing with it. You also have no way of knowing who updated the clipboard; you can only know that it changed."Even though this conclusion by a member of Microsoft VSTO Team Geoff Darst was drawn in response to the question of intercepting clipboard copy in Excel, this is related to how system works. The trick of using clipboard chain may or may not be sufficient for your goals. In all cases, it will need a really good effort to achieve.
—SA