GetClipboardData

  HANDLE GetClipboardData(wFormat)    
  UINT wFormat; /* data format */

This function retrieves data from the clipboard in the format given by the wFormat parameter. The clipboard must have been opened previously.

Parameters

wFormat

Specifies a data format. For a description of the data formats, see the SetClipboardData function, later in this chapter.

Return Value

The return value identifies the memory block that contains the data from the clipboard. The handle type depends on the type of data specified by the wFormat parameter. It is NULL if there is an error.

Comments

The available formats can be enumerated in advance by using the EnumClipboardFormats function.

The data handle returned by GetClipboardData is controlled by the clipboard, not by the application. The application should copy the data immediately, instead of relying on the data handle for long-term use. The application should not free the data handle or leave it locked.

Windows supports three formats for text, CF_UNICODETEXT, CF_TEXT and CF_OEMTEXT. CF_TEXT is specified for ansi text. CF_UNICODETEXT is specified for unicode text, and CF_OEMTEXT is specified for oem text. If an application calls GetClipboardData to retrieve data in one text format and one of the other text formats is the only available text format, Windows automatically converts the text to the requested format before supplying it to your application.

Windows supports two formats for metafiles, CF_ENHMETAFILE and CF_METAFILEPICT. CF_ENHMETAFILE is specified for the enhanced metafiles and CF_METAFILEPICT is specified for the Windows metafiles. If an application calls GetClipboardData to retrieve data in one metafile format and the other metafile format is the available metafile format, Windows automatically converts the metafile to the requested format before supplying it to the application. Only one metafile format can be set at a time. The new metafile replaces the previous metafile even if it is in a different format. An application needs to understand only one metafile format to display metafiles.

If the clipboard contains data in the CF_PALETTE (logical color palette) format, the application should assume that any other data in the clipboard is realized against that logical palette.

See Also

EnumClipboardFormats, SetClipboardData