| Tenouk C & C++ | MFC Home | OLE & Containers 6 | OLE & Containers 8 | Download | Site Index |


 

 

 

 

 

 

OLE Embedded Components and Containers part 7

 

 

 

 

 

 

 

Program examples compiled using Visual C++ 6.0 compiler on Windows XP Pro machine with Service Pack 2. The Excel version is Excel 2003/Office 11. Topics and sub topics for this tutorial are listed below. Don’t forget to read Tenouk’s small disclaimer. The supplementary notes for this tutorial are IOleObject and OLE.

  1. The EX32C Example: An OLE Embedded Component

  2. The EX32C from scratch

 

 

The EX32C Example: An OLE Embedded Component

 

You've already seen an MFC embedded component with in-place-activation capability (EX32A). Now you'll see a bare-bones component program that activates an embedded object in a separate window. It doesn't do much except display text and graphics in the window, but you'll learn a lot if you study the code. The application started as an SDI AppWizard Automation component with the document as the creatable object. The document's IDispatch interface was ripped out and replaced with IOleObject, IDataObject, and IPersistStorage interfaces. All the template server code carries through, so the document, view, and main frame objects are created when the container starts the component.

Open and build the EX32C project now. Run the application to register it, and then try it with the EX32B container or any other container program.

 

The EX32C from scratch

 

This is SDI application with Automation support and no ActiveX Controls.

 

Figure 1: EX32C – Visual C++ new project dialog.

 

Figure 1: EX32C – Visual C++ new project dialog.

 

Select a Single document option.

 

Figure 2: EX32C – AppWizard step 1 of 6.

 

Figure 2: EX32C – AppWizard step 1 of 6.

 

Figure 3: EX32C – AppWizard step 2 of 6.

 

Figure 3: EX32C – AppWizard step 2 of 6.

 

Select Automation option and deselect ActiveX Controls.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 4: EX32C – AppWizard step 3 of 6.

 

Figure 4: EX32C – AppWizard step 3 of 6.

 

Figure 5: EX32C – AppWizard step 4 of 6.

 

Figure 5: EX32C – AppWizard step 4 of 6.

 

Figure 6: EX32C – AppWizard step 5 of 6.

 

Figure 6: EX32C – AppWizard step 5 of 6.

 

Figure 7: EX32C – AppWizard step 6 of 6.

 

Figure 7: EX32C – AppWizard step 6 of 6.

 

 

Figure 8: EX32C project summary.

 

Figure 8: EX32C project summary.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Delete the file related menu items then replace them with Update menu item.

 

Figure 9: Replacing file related menus with Update.

 

Figure 9: Replacing file related menus with Update.

 

Edit the Exit menu item.

 

Figure 10: Editing the Exit menu item.

 

Figure 10: Editing the Exit menu item.

 

Add the following menu and its’ items.

 

Figure 11: Adding menu and its’ items.

 

Figure 11: Adding menu and its’ items.

 

Figure 12: Adding Modify menu.

 

Figure 12: Adding Modify menu.

 

Add dialog and edit control.

 

Figure 13: Adding dialog and Edit control.

 

Figure 13: Adding dialog and Edit control.

 

Figure 14: Edit control property.

 

Figure 14: Edit control property.

 

Launch ClassWizard to add new class, CTextDialog for Dialog.

 

Figure 15: Adding new class for the previous dialog prompt.

 

Figure 15: Adding new class for the previous dialog prompt.

 

Figure 16: Adding CTextDialog class and its information.

 

Figure 16: Adding CTextDialog class and its information.

 

 

Add member variable and set the maximum value to 100.

 

Figure 17: Adding m_strText member variable to IDC_TEXT Edit control of CTextDialog class.

 

Figure 17: Adding m_strText member variable to IDC_TEXT Edit control of CTextDialog class.

 

Figure 18: The added member variable.

 

Figure 18: The added member variable.

 

Add/override ExitInstance() to CEx32cApp class.

 

Figure 19:  Adding ExitInstance() to CEx32cApp class.

 

Figure 19:  Adding ExitInstance() to CEx32cApp class.

 

Add/override OnPrepareDC() to CEx32cView class.

 

Figure 20: Adding OnPrepareDC() to CEx32cView class.

 

Figure 20: Adding OnPrepareDC() to CEx32cView class.

 

Add OnCloseDocument(), OnFinalRelease() and SaveModified() to CEx32cDoc class.

 

Figure 21: Add OnCloseDocument(), OnFinalRelease() and SaveModified() to CEx32cDoc class.

 

Figure 21: Add OnCloseDocument(), OnFinalRelease() and SaveModified() to CEx32cDoc class.

 

Add the following commands and update command.

 

 

Figure 22: Adding commands and update command to CEx32cDoc class.

 

Figure 22: Adding commands and update command to CEx32cDoc class.

 

 

 

 

 

 

 

 

 

Further reading and digging:

  1. DCOM at MSDN.

  2. COM+ at MSDN.

  3. COM at MSDN.

  4. Win32 process, thread and synchronization story can be found starting from Module R.

  5. MSDN MFC 7.0 class library online documentation.

  6. MSDN MFC 9.0 class library online documentation - latest version.

  7. MSDN Library

  8. Windows data type.

  9. Win32 programming Tutorial.

  10. The best of C/C++, MFC, Windows and other related books.

  11. Unicode and Multibyte character set: Story and program examples.

 

 


 

| Tenouk C & C++ | MFC Home | OLE & Containers 6 | OLE & Containers 8 | Download | Site Index |