Visual C++ 6 Unleashed

Visual C++ 6 Unleashed

By MICKEY WILLIAMS and David Bennett

The COM Interfaces

Nine COM interfaces are part of the active document container specification. Six of these interfaces were part of the OLE container specification, and the other three are new to active document containers. Two of the new interfaces—IOleCommandTarget and IContinueCallback—are optional. Table 26.1 lists the COM interfaces with the corresponding MFCs that implement the interface.

Table 26.1. COM Interfaces Used By Containers

COM Interface Type MFC
IOleInPlaceFrame OLE 2.0 COleControlContainer
IOleCommandTarget New, optional None
IOleInPlaceUIWindow OLE 2.0 COleControlContainer
IOleContainer OLE 2.0 COleControlContainer
IOleClientSite OLE 2.0 COleClientItem
IAdviseSink OLE 2.0 COleClientItem
IOleDocumentSite New, required None
IOleInPlaceSite OLE 2.0 COleClientItem
IContinueCallback New, optional None

This section discusses these interfaces in more detail.

IOleInPlaceFrame

IOleInPlaceFrame is a COM interface derived from three other COM interfaces: IOleInPlaceUIWindow, IOleWindow, and IUnknown. IOleInPlaceFrame controls the top-level frame window of the container. With this interface, it is possible to add and remove items from the composite menu, set status text, manage modeless dialog boxes, and translate accelerator keys. Each of the interfaces that IOleInPlaceFrame derives from contributes required methods. Table 26.2 describes these interfaces.

Table 26.2. IOleInPlaceFrame Interfaces

Interface Description
  IUnknown Methods
AddRef Adds a reference count to the object
QueryInterface Discovers required interfaces
Release Decrements the reference count for the object and eventually deletes the object
  IOleWindow Methods
ContextSensitiveHelp Gives the container the opportunity to handle context-sensitive help
GetWindow Gets the window handle to the frame, document, parent, or in-place object
  IOleInPlaceUIWindow Methods
GetBorder Returns the rectangle where ActiveX documents can put their toolbars and other controls
RequestBorderSpace Asks the container for space for toolbars and other controls
SetBorderSpace Tells the container to allocate the space for toolbars and other controls
  IOleInPlaceUIWindow Methods
SetActiveObject Called by the ActiveX document to create a link between itself and the active document container
  IOleInPlaceFrame Methods
EnableModeless Enables or disables modeless dialog boxes at the frame level
InsertMenus Allows the container to insert its menu items into the shared menu
RemoveMenus Allows the container to remove its menu items
SetMenu Allows the ActiveX document to install the merged container/document menu
SetStatusText Displays status text in the static area
TranslateAccelerator Translates accelerator keystrokes intended for the container

IOleCommandTarget

IOleCommandTarget allows client and server to dispatch commands to each other. With the active document container, IOleCommandTarget allows the active document to route commands that it generates to the container. Table 26.3 describes the interfaces.

Table 26.3. IOleCommandTarget Interfaces

Interface Description
  IUnknown Methods
AddRef Adds a reference count to the object
QueryInterface Discovers required interfaces
Release Decrements the reference count for the object and eventually deletes the object
  IOleCommandTarget Methods
Exec Executes the requested command
QueryStatus Asks the object whether it supports a particular type of command

IOleInPlaceUIWindow

IOleInPlaceUIWindow allows active documents to negotiate border space in the frame window. The interface manages the allocation of border space and the interaction between the document and the frame. IOleInPlaceUIWindow derives from IOleWindow. Table 26.4 describes the interfaces.

Table 26.4. IOleInPlaceUIWindow Interfaces

Interface Description
  IUnknown Interfaces
AddRef Adds a reference count to the object
QueryInterface Discovers required interfaces
Release Decrements the reference count for the object and eventually deletes the object
  IOleWindow Interfaces
ContextSensitiveHelp Gives the container the opportunity to handle context-sensitive help
GetWindow Gets the window handle to the frame, document, parent, or in-place object
  IOleInPlaceUIWindow Methods
GetBorder Returns the rectangle where ActiveX documents can put their toolbars and other controls
RequestBorderSpace Asks the container for space for toolbars and other controls
SetActiveObject Called by the ActiveX document to create a link between itself and the active document container
SetBorderSpace Tells the container to allocate the space for toolbars and other controls

IOleContainer

IOleContainer queries objects in a compound document or locks the container in the running state. This interface is useful only when the container supports linked objects and requires both the container and the document to implement it. Table 26.5 describes the interfaces.

Table 26.5. IOleContainer Interfaces

Interface Description
  IUnknown Interfaces
AddRef Adds a reference count to the object
QueryInterface Discovers required interfaces
Release Decrements the reference count for the object and eventually deletes the object
  IParseDisplayName Methods
ParseDisplayName Parses a display name into something usable by a moniker
  IOleContainer Methods
EnumObjects Enumerates objects in the container
LockContainer Keeps the container locked in running mode until it is explicitly released

IOleClientSite

IOleClientSite helps an active document get information about its container environment. It can get information about its display area as well as other user interface information from the container. Table 26.6 describes the interfaces.

Table 26.6. IOleClientSite Interfaces

Interface Description
  IUnknown Interfaces
AddRef Adds a reference count to the object
QueryInterface Discovers required interfaces
Release Decrements the reference count for the object and eventually deletes the object
  IOleClientSite Methods
GetContainer Returns a pointer to the container's IOleContainer interface
GetMoniker Creates a moniker to access the embedded active document
OnShowWindow Notifies the container when an object is about to become visible or invisible; does not apply to active documents or other in-place activated objects
  IOleClientSite Methods
RequestNewObjectLayout Asks the container to provide more or less space for displaying the active document
SaveObject Saves the active document associated with this site
ShowObject Positions the active document so that it is visible to the user; makes sure the container itself is visible to the user

IAdviseSink

IAdviseSink provides a way for active documents to notify their containers when their data or states change. Table 26.7 describes the interfaces.

Table 26.7. IAdviseSink Interfaces

Interface Description
  IUnknown Interfaces
AddRef Adds a reference count to the object
QueryInterface Discovers required interfaces
Release Decrements the reference count for the object and eventually deletes the object
  IAdviseSink Methods
OnClose Called when the active document has been closed
OnDataChange Called when the data has changed
OnRename Called when the name has changed
OnSave Called when the active document has been saved to disk
OnViewChange Called when the view has changed

IOleDocumentSite

IOleDocumentSite allows an active document to bypass the normal activation sequence for an in-place object and activate directly as a document object. Table 26.8 describes the interfaces.

Table 26.8. IOleDocumentSite Interfaces

Interface Description
  IUnknown Interfaces
AddRef Adds a reference count to the object
QueryInterface Discovers required interfaces
Release Decrements the reference count for the object and eventually deletes the object
  IOleDocumentSite Methods
ActivateMe Actives the active document as a document object instead of an in-place object

IOleInPlaceSite

IOleInPlaceSite works with IOleDocumentSite. For each view an active document instantiates, an IOleInPlaceSite object must exist. IOleDocumentSite manages one or more IOleInPlaceSite objects. The IOleInPlaceSite interface provides methods that manage the active document. Table 26.9 describes the interfaces.

Table 26.9. IOleInPlaceSite Interfaces

Interface Description
  IUnknown Interfaces
AddRef Adds a reference count to the object
QueryInterface Discovers required interfaces
Release Decrements the reference count for the object and eventually deletes the object
  IOleWindow Methods
ContextSensitiveHelp Gives the container the opportunity to handle context-sensitive help
GetWindow Gets the window handle to the frame, document, parent, or in-place object
  IOleInPlaceSite Methods
CanInPlaceActivate Gives the object permission to in-place activate
DeactivateAndUndo Tells the container to end the in-place active session and return to its Undo state
DiscardUndoState Tells the container to discard its Undo state
  IOleInPlaceSite Methods
GetWindowContext Provides window hierarchy information
OnInPlaceActivate Notifies the container that the ActiveX document is about to in-place activate
OnInPlaceDeactivate Tells the container that the ActiveX document is no longer in-place active
OnPosRectChange Used by the active document to tell the container that its size has changed
OnUIActivate Called when the active document is about to in-place activate and replace the menu with a composite menu
OnUIDeactivate Tells the container that the ActiveX document is going away and that the container should restore its user interface
Scroll Tells the container how to scroll the object

IContinueCallback

IContinueCallback helps the active document ask the container whether it should continue an interruptible process. This feature is used with the active document's IPrint interface. Table 26.10 describes the interfaces.

Table 26.10. IContinueCallback Interfaces

Interface Description
  IUnknown Interfaces
AddRef Adds a reference count to the object
QueryInterface Discovers required interfaces
Release Decrements the reference count for the object and eventually deletes the object
  IContinueCallback Methods
FContinue Used by printing tasks to determine whether printing should continue
FContinuePrinting Used by the printing tasks to determine whether the task should continue; also provides some progress information

You can find more information about these COM interfaces in the Visual C++ Help system. The system also provides good background information on the world of COM, OLE, and other Active technologies. Another interesting exercise is to search through the MFC source code to see where Microsoft has implemented these and other COM interfaces in the MFC Library. The MFC source code is located in the \Vc98\Mfc subdirectory.

Share ThisShare This

Informit Network