6.3.10 Client Cut and Copy Commands

A client application can copy an object to the clipboard by simply opening the clipboard, calling the OleCopyToClipboard function, and closing the clipboard again. If the client supports delayed rendering, however, it should follow these steps to cut or copy an object to the clipboard:

1.Open and empty the clipboard.

2.Put the preferred data formats on the clipboard.

3.Call the OleEnumFormats function to retrieve the formats for the object.

4.Call the SetClipboardData function to put the formats on the clipboard, specifying NULL for the handle of the data.

If the call to the OleEnumFormats function retrieves the ObjectLink format, the client should call SetClipboardData with OwnerLink instead of ObjectLink format. (For more information, see the following description of the OleCopyToClipboard function.)

5.Put any additional presentation data formats on the clipboard.

6.Close the clipboard.

To support the Cut command on the Edit menu, an application can call OleCopyToClipboard and then delete the object by using the OleDelete function. (The client can put only one of the selected objects on the clipboard, even when the user has selected and cut or copied multiple objects. In this case, the client typically puts the first object in the selection onto the clipboard.)

The OleCopyToClipboard function always copies OwnerLink format, not ObjectLink format, to the clipboard. For embedded objects, Native data always precedes the OwnerLink format. If a linked object uses Native data, OwnerLink format always precedes the Native data. If an application uses the OleGetData function to retrieve data from a linked object that has been copied by using OleCopyToClipboard, it should specify ObjectLink format, not OwnerLink format, even if OwnerLink format was put on the clipboard.

When an application that can act as both a client and server copies a selection to the clipboard that contains one or more objects, it should first allocate enough memory for the selection. To discover how much memory is required for each object, the application can call the OleQuerySize function. When memory has been allocated, the application should call the OleRegisterClientDoc function, specifying Clipboard for the document name. (In this case, the handle returned by the call to OleRegisterClientDoc identifies a document that is used only during the copy operation.) To save each object to memory, the application calls the OleClone function, calls the OleSaveToStream function for the cloned object, and then calls the OleRelease function to free the memory for the cloned object. When the selection has been saved to the stream, the application can call the SetClipboardData function. If SetClipboardData is successful, the application should call the OleSavedClientDoc function. The application then calls the OleRevokeClientDoc function, specifying the handle retrieved by the call to OleRegisterClientDoc.

For more information about the Cut and Copy commands, see Section 6.4.3, “Server Cut and Copy Commands.”