Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
How To Add HTML Code to the Clipboard by Using Visual C++
Article ID: 274308 - View products that this article applies to.
This article was previously published under Q274308
This article demonstrates how to add Hypertext Markup Language (HTML) to the Microsoft Windows clipboard by using Visual C++. It also includes a sample function that you can use in your applications to simplify the process.
HTML has its own clipboard format called HTML Format (CF_HTML) that you can use to provide your data to other applications, such as Microsoft Excel, Microsoft Word, or other Microsoft Office applications.
CF_HTML is entirely a text-based format that includes a description, a context, and a fragment within that context. When you build data to send to the clipboard, you must include a description of the data to indicate the clipboard version and the offsets for the context and fragment. Calculating the offsets can be the difficult part. However, you can use the following routine to simplify this task:
When you use this function to copy an HTML code fragment to the clipboard, it might look like the following:
Additional NoteUsing an approach that sends HTML code to the clipboard might be especially beneficial for Office Automation clients. For example, if you have an Automation client that needs to generate formatted data for cells in Microsoft Excel or paragraphs in Microsoft Word, you could build the data in HTML code, send it to the clipboard, and then paste it into the application. By using this technique, you could reduce the number of out-of-process calls to the Automation client.
To learn more about the specifics of the HTML Clipboard format, see the topic "HTML Clipboard Format" in the MSDN: