Deleting Embedded Objects
To clear, or delete, an embedded object, you must:
Add a Delete command to the Edit menu in the
IDR_CONTRTYPE
menu and assign its command IDCreate handlers for the new Delete command
Implement code for the handlers.
The following procedure explains how to do these tasks.
Note For a refresher on working with the menu editor, complete the procedure outlined in Add the Clear All Command to Scribble's Edit Menu in Scribble Lesson 5.
To delete an embedded object
Use the menu editor to add a Delete command and separator to the Edit menu in the
IDR_CONTRTYPE
menu resource:Edit
...
Paste &Special
-------------
&Delete
-------------
Assign the standard framework command ID, ID_EDIT_CLEAR, to the Delete command. Note that the command prompt is already defined for you by the framework:
Erase the selection\nErase
(The prompt doesn’t show until you’re out of edit mode for this menu command.)
Save the resource file.
Using WizardBar, create a pair of ON_COMMAND and ON_UPDATE_COMMAND_UI handlers for ID_EDIT_CLEAR in ContainerView.cpp.
Implement
OnEditClear
as follows:if (m_pSelection != NULL) { m_pSelection->Delete(); m_pSelection = NULL; GetDocument()->UpdateAllViews(NULL); }
Implement
OnUpdateEditClear
as follows:pCmdUI->Enable(m_pSelection != NULL);
To delete an embedded object in a container, simply call the object’s COleClientItem::Delete function.