How does Copy Paste of formatted text work?

The data on the clipboard is extended with FORMATETC records:

http://msdn.microsoft.com/en-us/library/ms682177%28VS.85%29.aspx

The FORMATETC record contains as first field a cfFormat member which describes the file format. cfFormat can be a predefined value like CF_UNICODETEXT or CF_BITMAP or an application defined type defined by e.g. Microsoft Word.

In .NET you can apparently query the Clipboard object to find out which data formats it contains:

http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.aspx

The method you are looking for is Clipboard.SetData:

If you do not know the format of the target application, you can store data in multiple formats using this method.

Data stored using this method can be converted to a compatible format when it is retrieved.

To retrieve data from the Clipboard in a particular format, first use the ContainsData method to determine whether the Clipboard contains data in that format before retrieving it with the GetData method

As to your concrete question how it works in Word, the above links should give you enough information to write a little clipboard viewer yourself. Since Microsoft Word is able to output HTML files, my guess is that Word writes the data on the clipboard as simple Text, HTML, RTF and in Word format.

Leave a Comment

techhipbettruvabetnorabahisbahis forumuedusedusedusedueduseduseduseduedusedus