In-Place Objects Step by Step

First you need an embedded object. Got one? Great, let's make it in-place capable by adding IOleInPlaceObject to the interfaces the object already has and providing an implementation of IOleInPlaceActiveObject. Well, let's not jump in quite so fast. There are crocodiles in the river. In-place activation carries some heavy implications for your object and server. So when implementing in-place activation, you should address these implications before adding anything related to in-place interfaces. Most of these implications have to do with the fact that you are going to be placing windows and menu items in a container application, so you have to check for assumptions that exist in your server windows exclusively. This may or may not be a major issue for you, but I hope to have you thinking about it before you get in too deep.

Given that deflating remark, here's how we'll progress through this chapter:

Prepare your object for the implications of in-place activation.

Implement skeletal IOleInPlaceObject and IOleInPlaceActiveObject interfaces and create some stubs for a few useful internal functions in your object.

Modify DoVerb to begin activation for the appropriate verbs and to provide for simple deactivation. This excludes most of the user interface.

Create, manage, and disassemble the shared menu.

Negotiate and create your in-place tools.

Modify your accelerators and your message loop to share the keyboard with the container.

Complete your implementation of the two in-place interfaces and add small fragments of code to round out your in-place object. This section, like the one in Chapter 22, is the catchall for the little fish that tend to slip through big nets. Here we'll also look briefly at inside-out objects.

The following sections describe these steps using Cosmo (CHAP23\COSMO) as an example. This chapter also includes an in-place–capable version of Polyline (CHAP23\POLYLINE) that behaves almost exactly the same way as Cosmo except that it doesn't have any menus or toolbars. Polyline is a simpler case of an in-place object, which makes a nice foundation for creating an OLE control in Chapter 24.

I have not provided an updated version of the HCosmo handler that we saw in Chapter 19. The registry files used for Cosmo in this chapter specify the default handler as the InprocHandler32 entry. If you encounter odd problems when working with Cosmo here, check the handler entry and be sure it specifies the default handler.