Embedding Containers Step by Step: Patron

The remainder of this chapter will follow modifications I made to Patron (CHAP17\PATRON) to make it a container for embedded objects. Patron includes most of those items listed in the previous section, but it does not implement message filtering or the Busy dialog box. Such support is easily added using the code illustrated in Chapter 6.

Support for embedding requires changes at many levels, much of it having to do with the user interface. If we return to our cookie jar metaphor for a moment, the cookies need to define the user interface only to account for how they look, feel, and taste—very cookie-oriented sorts of stuff. The cookie jar has to define how it opens and how it looks from the outside. In the same manner, the shelf on which the cookie jar rests has its own interface of color and dimension, just as the kitchen and the house have to define their own characteristics. So, in much the same way that most of the user interface in a house is shown in rooms, shelves, and storage devices, most of the user interface in OLE Documents falls on the container.

Nevertheless, we can reduce implementation to the following sequence of steps; all of the steps except step 1 are elaborated in the following sections. These steps are organized so that you can at least compile after coding the step. In most cases, you will also have something you can run and test. I strongly recommend that you test as much as you can in the early steps because the later ones build on these foundations; testing simplifies the overall task of writing a container.4

Initialize OLE on startup and uninitialize on shutdown using OleInitialize and OleUninitialize.

Implement IOleClientSite and IAdviseSink on your site object and add variables to manage the content object that will be stored in each site.

Implement site shading to be used from IOleClientSite::OnShowWindow, and draw the object to a screen or printer.

Invoke the Insert Object dialog box, and create and initialize objects on return.

Activate the object on a double click, and add an object verb menu. Also implement a right mouse button pop-up menu.

Add the ability to paste an object from the clipboard (through the Paste Special command if desired), or accept one through drag and drop.

Provide new data formats to copy an embedded object back to the clipboard or to source it in a drag-and-drop operation.

Delete objects from the document, and call CoFreeUnusedLibraries.

Save and load documents containing embedded objects.

Invoke the Convert dialog box, and handle the Convert To case, the Activate As case, and the Display As Icon changes. Handling iconic presentations includes working with the cache.

4 There are a few additional concerns for dealing with OLE 1 servers, as documented in the file OLE1.WRI on the companion CD.