Deleting Embedded Objects

To clear, or delete, an embedded object, you must:

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

  1. 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

    -------------

  2. 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.)

  3. Save the resource file.

  4. Using WizardBar, create a pair of ON_COMMAND and ON_UPDATE_COMMAND_UI handlers for ID_EDIT_CLEAR in ContainerView.cpp.

  5. Implement OnEditClear as follows:
    if (m_pSelection != NULL)
    {
    m_pSelection->Delete();
    m_pSelection = NULL;
    GetDocument()->UpdateAllViews(NULL);
    }
    
  6. 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.