Article ID: 120682
Article Last Modified on 11/21/2006
COleInsertDialog::m_io Structure of type OLEUIINSERTOBJECT used to control the behavior of the Insert Object dialog box. Members of this structure can be modified either directly or through member functions.The OLEUIINSERTOBJECT dialog contains two members which allow the user to exclude specific object types from the dialog's selection list by CLSID. The member lpClsidExclude is a pointer of type LPCLSID and therefore must point directly to a variable of type CLSID. The member cClsidExclude is a UINT and contains the number of CLSID types that are pointed to by lpClsidExclude. If you want to exclude more than one CLSID, use an array.
// This identifier was generated to be statistically unique for your app.
// You may change it if you prefer to choose a specific identifier.
static const CLSID BASED_CODE clsid = { 0x565295c6, 0xc992, 0x11cd,
{ 0x96, 0xf2, 0x0, 0xaa, 0x0, 0x3b, 0x80,0x67 } };
For the purpose of accessing clsid from a view class member function,
take the "static" storage class off the above declaration.
/* AppWizard generated OnInsertObject() function modified to
* exclude our own object type from the OLE Insert Object Dialog.
*/
void CSvrcntrView::OnInsertObject()
{
// Invoke the standard Insert Object dialog box to obtain information
// for new CSvrcntrCntrItem object.
COleInsertDialog dlg;
// Our own object's clsid - don't insert it!
dlg.m_io.lpClsidExclude = (LPCLSID) &clsid;
dlg.m_io.cClsidExclude = 1; // Number of clsid's in the array.
if (dlg.DoModal() != IDOK)
return;
BeginWaitCursor();
CSvrcntrCntrItem* pItem = NULL;
TRY
{
// Create new item connected to this document.
CSvrcntrDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pItem = new CSvrcntrCntrItem(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();
}
Additional query words: kbinf 1.50 2.00 2.50 3.00
Keywords: KB120682