How to insert objects without using the InsertObject dialog box by using Visual C++
This article was previously published under Q137357 Note Microsoft Visual C++ .NET (2002) supports both the managed code
model that is provided by the Microsoft .NET Framework and the unmanaged native
Microsoft Windows code model. The information in this article applies only to
unmanaged Visual C++ code. Note Microsoft Visual C++ 2005 supports both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model. On This PageSUMMARY When building an OLE container or OLE server application
using MFC OLE classes, you should insert an OLE embedded object
programmatically, without using the InsertObject dialog box. This article show
you how. In a default MFC AppWizard-generated OLE container or OLE server application, a command handler is implemented to enable the user to insert an object by clicking Insert New Object on the Edit menu. The AppWizard-generated code makes use of the COleInsertDialog class, which is an MFC wrapper for the OLEUIINSERTOBJECT common dialog box. The COleInsertDialog data and member functions are used to embed the object. MORE INFORMATION The member function most responsible for the embedding of
an OLE object is COleInsertDialog::CreateItem, which takes a pointer to a
COleClientItem as a formal parameter. When the user clicks Insert New Object on the Edit menu, a COleInsertDialog is created, and it is shown by calling its DoModal function. When the dialog box is dismissed, some of its data members are set by selections made by the user, such as Create From File or Create New. The implementation of COleInsertDialog::CreateItem calls the COleClientItem member functions to embed the object, which leads to the solution of by- passing the COleInsertDialog class and calling COleClientItem to do the work. Here is an excerpt from COleInsertDialog::CreateItem: This code features a switch structure whose logic flow is controlled by
the selType set by the user interaction with the COleInsertDialog dialog
box.The following code demonstrates how to insert an OLE embedded object programmatically. The code shows the creation of an instance of a COleClientItem object, which then calls its CreateNewItem member function to create and embed a Microsoft Excel worksheet. Sample codeAPPLIES TO
| Article Translations
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

Back to the top
