void CDiscoverMDIView::OnInsertObject() { // Invoke the standard Insert Object dialog box to obtain information // for new CDiscoverMDICntrItem object. COleInsertDialog dlg; if (dlg.DoModal() != IDOK) return; BeginWaitCursor(); CDiscoverMDICntrItem* pItem = NULL; TRY { // Create new item connected to this document. CDiscoverMDIDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pItem = new CDiscoverMDICntrItem(pDoc); ASSERT_VALID(pItem); // Initialize the item from the dialog data. if (!dlg.CreateItem(pItem)) AfxThrowMemoryException(); // any exception will do ASSERT_VALID(pItem); // If item created from class list (not from file) then launch // the server to edit the item. if (dlg.GetSelectionType() == COleInsertDialog::createNewItem) pItem->DoVerb(OLEIVERB_SHOW, this); ASSERT_VALID(pItem); // As an arbitrary user interface design, this sets the selection // to the last item inserted. // TODO: reimplement selection as appropriate for your application m_pSelection = pItem; // set selection to last inserted item pDoc->UpdateAllViews(NULL); } CATCH(CException, e) { if (pItem != NULL) { ASSERT_VALID(pItem); pItem->Delete(); } AfxMessageBox(IDP_FAILED_TO_CREATE); } END_CATCH EndWaitCursor(); }
void CDrawView::OnInsertObject() { // Invoke the standard Insert Object dialog box to obtain information // for new CDrawItem object. COleInsertDialog dlg; if (dlg.DoModal() != IDOK) return; BeginWaitCursor(); // First create the C++ object CDrawOleObj* pObj = new CDrawOleObj(GetInitialPosition()); ASSERT_VALID(pObj); CDrawItem* pItem = new CDrawItem(GetDocument(), pObj); ASSERT_VALID(pItem); pObj->m_pClientItem = pItem; // Now create the OLE object/item TRY { if (!dlg.CreateItem(pObj->m_pClientItem)) AfxThrowMemoryException(); // add the object to the document /*GetDocument()->*/g_pGuiManager->AddBack(pObj); pObj->m_pDocument = GetDocument(); GetDocument()->SetModifiedFlag(); // try to get initial presentation data pItem->UpdateLink(); pItem->UpdateExtent(); // if insert new object -- initially show the object if (dlg.GetSelectionType() == COleInsertDialog::createNewItem) pItem->DoVerb(OLEIVERB_SHOW, this); } CATCH_ALL(e) { // clean up item pItem->Delete(); pObj->m_pClientItem = NULL; /*GetDocument()->*/g_pGuiManager->Remove(pObj); GetDocument()->SetModifiedFlag(TRUE); pObj->Remove(); AfxMessageBox(IDP_FAILED_TO_CREATE); } END_CATCH_ALL EndWaitCursor(); }