Using the Clipboard

To copy data to the clipboard, you format the data using either a predefined or private format. For most formats, you allocate global memory and copy the data into it. You then use the SetClipboardData function to copy the memory handle to the clipboard.

In Windows applications, copying and pasting are carried out through Edit-menu commands. For a description of how to add the Edit menu to an application, see Chapter 7, “Menus.”

Windows provides several predefined data formats for use in data interchange. Following is a list of common formats and their contents:

Format Contents

CF_TEXT Null-terminated text
CF_OEMTEXT Null-terminated text in the OEM character set
CF_METAFILEPICT Metafile-picture structure
CF_BITMAP A device-dependent bitmap
CF_DIB A device-independent bitmap
CF_SYLK SYLK standard data-interchange format
CF_DIF DIF standard data-interchange format
CF_TIFF TIFF standard data-interchange format

When you paste data from the clipboard using the GetClipboardData function, you specify the format you expect. The clipboard supplies the data only if it has been copied in that format.

Windows supports two formats for text, CF_TEXT and CF_OEMTEXT. CF_TEXT is the default Windows text clipboard format. Windows uses the CF_OEMTEXT format for text in non-Windows applications. If you call GetClipboardData to retrieve data in one text format and the other text format is the only available text format, Windows automatically converts the text to the requested format before supplying it to your application.

NOTE:

Clipboard data objects can be any size. Your application must be able to work with clipboard data objects larger than 64K. For more information on working with large data objects, see Chapter 26, “Memory Management.”