This article describes the minimum work necessary to implement copying to and pasting from the Clipboard in your OLE application. It is recommended that you read the Data Objects and Data Sources (OLE) family of articles before proceeding.
Before you can implement either copying or pasting, you must first provide functions to handle the Copy, Cut, and Paste options on the Edit menu.
To copy data to the Clipboard
To see an example of this sequence, see the OnEditCut and OnEditCopy functions in the MFC OLE sample programs OCLIENT and HIERSVR. Note that these samples maintain a pointer to the currently selected data, so step 1 is already complete.
Pasting data is more complicated than copying it because you need to choose the format to use in pasting the data into your application.
To paste data from the Clipboard
Alternately, you can use COleDataObject::BeginEnumFormats to look for other formats until you find one most suited to your application.
For an example of how this works, see the implementation of the OnEditPaste member functions in the view classes defined in the MFC OLE sample programs OCLIENT and HIERSVR.
Tip The main benefit of separating the paste operation into its own function is that the same paste code can be used when data is dropped in your application during a drag-and-drop operation. As in OCLIENT and HIERSVR, your OnDrop function can also call DoPasteItem, reusing the code written to implement Paste operations.
To handle the Paste Special option on the Edit menu, see the article Dialog Boxes in OLE.