Home | Overview | How Do I | Sample | Tutorial
After a data object or data source has been created, you can perform a number of common operations on the data, such as inserting and removing data, enumerating the formats the data is in, and more. This article describes the techniques necessary to complete the most common operations. Topics include:
How data is inserted into a data source depends on whether the data is supplied immediately or on demand, and in which medium it is supplied. The possibilities are as follows.
-or-
This is an advanced topic.
-or-
Before an application allows the user to paste data into it, it needs to know if there are formats on the Clipboard that it can handle. To do this, your application should do the following:
-or-
If you are using ON_UPDATE_COMMAND_UI, you can now enable the Paste and, possibly, Paste Special items on the Edit menu. To do this, call either CMenu::EnableMenuItem or CCmdUI::Enable. For more information on what container applications should do with menu items and when, see the Menus and Resources: Container Additions article.
Once you have decided on a data format, all that’s left is to retrieve the data from the data object. To do this, the user decides where he or she wants to put the data, and the application calls the appropriate function. The data will be available in one of the following mediums:
Medium | Function to call |
Global Memory (HGLOBAL) | COleDataObject::GetGlobalData |
File (CFile) | COleDataObject::GetFileData |
STGMEDIUM structure (IStorage) | COleDataObject::GetData |
Commonly, the medium will be specified along with its Clipboard format. For example, a CF_EMBEDDEDSTRUCT object is always in an IStorage medium that requires an STGMEDIUM structure. Therefore, you would use GetData because it is the only one of these functions that can accept an STGMEDIUM structure.
For cases where the Clipboard format is in an IStream or HGLOBAL medium, the framework can provide a CFile pointer that references the data. The application can then use file read to get the data in much the same way as it might import data from a file. Essentially, this is the client-side interface to the OnRenderData and OnRenderFileData routines in the data source.
The user can now insert data into the document just like for any other data in the same format.
See Also COleDataObject, COleDataSource