Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
With a Web-Browser object (or Internet Explorer) the user can select a portion of the html document by doing a mouse drag operation. This portion can then be sent to the clipboard for instance. I want to access the selection the user has chosen and modify it before it is copied to the clipboard. Can anyone help with how to do this?

Thanks for the info about the clipboard but this is of little use.

I need to access the selection from the webbrowser object. Somewhere there must be a start and end point defined which shows the portion of the HTML document that the user has selected before it gets anywhere near the clipboard. Since the webbrowser shows the selection highlighted, it must have access to the portion of the document selected. It is those start and end points which I need to modify in my app.

Any ideas?
Posted
Updated 5-May-11 3:12am
v3
Comments
HimanshuJoshi 4-May-11 19:17pm    
Removed bold tag from the question.

1 solution

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
 
Share this answer
 
v2
Comments
Prasanta_Prince 4-May-11 22:27pm    
Good one SA. 5 from me.
Sergey Alexandrovich Kryukov 4-May-11 22:29pm    
Thank you, Prasanta,
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900