Choosing formats when putting data on clipboard

The topic is from a forum discussion at http://social.msdn.microsoft.com/Forums/en/windowssdk/thread/94bb2db4-3ca2-4cd8-9f7c-6dd9aab6fd18

Generally an application should provide data in as many formats as possible so more applications can recognize the data. For example, IE stores text data in CF_UNICODETEXT, CF_TEXT and CF_HTML formats.

Because a lot of application would stop enumerating the clipboard on first supported format, to avoid data lose in round trips, clipboard formats that contain the most information should be placed on the clipboard first, followed by less descriptive formats. For example, CF_HTML first, CF_UNICODETEXT second and CF_TEXT last. Sometimes you get to choose from the paste format (e.g. paste special in Microsoft Word), but that’s the exception, not many program can paste the format that is not the first supported format (e.g. you don’t have paste special in Microsoft Paint).

Of course sometimes you want to limit, say, the format being exposed to the clipboard, e.g. when copying code from Visual Studio but expect the code to make a round trip back to Visual Studio without the formatting, then you may want to put a less descriptive format first. 

If using the webbrowser control as the text editor, you can remove the formatting in pasting by implementing OnFilterDataObject.

 

About Sheng Jiang 蒋晟

Microsoft MVP in Visual C , 2004- Forum moderator of the Visual C and .Net forums on CSDN Forum moderator of Chinese forums on Microsoft's MSDN forums
This entry was posted in enmsdn, Webbrowser control and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s