Summary

A viewable object is any object that implements IViewObject2 alongside any other interfaces. (IViewObject2 is a refinement of IViewObject, an earlier OLE interface.) Through IViewObject2, a client can have an object draw graphical presentations directly to a screen or printer device, using the member function named Draw. Draw gives a viewable object direct access to a device, defines how the object should scale its output, and provides for drawing into metafiles and breaking out of long repaints. Because Draw takes an hDC argument, however, IViewObject2 can be implemented only from an in-process object. A Windows hDC cannot be shared across process boundaries.

Nevertheless, IViewObject2 is a powerful interface. Other member functions allow the client to control changes to graphic presentations (for printer banding) and also to receive asynchronous notifications when a view changes. These notifications occur through IAdviseSink::OnViewChange and are distinct from data change notifications sent through IAdviseSink::OnDataChange. The latter function is useful for synchronizing an in-process implementation of a viewable object with a data source in a local server.

Related to an object's ability to draw its own presentations is its ability to cache those presentations in a piece of storage. A client can use such cached information to later display or print object presentations without requiring the object code to be present. OLE itself provides a data cache service. The cache is an object that implements not only IViewObject2 but also IPersistStorage, IDataObject, IOleCache2, and IOleCacheControl. Through these interfaces, the cache can save and load presentations, render the presentations as data formats, control what is stored in the cache, and connect to a running object in a local server from which the cache can automatically obtain updated presentations.

This chapter demonstrates the use of the cache as well as the client side of IViewObject2 by showing how an application can display, print, save, and reload metafiles and bitmaps without doing much work at all. The chapter's example sets the stage for enhancements to the Patron application in later chapters.