The File Menu

Chapter 25 - Getting Started with OLE

Visual C++ 6: The Complete Reference
Chris H. Pappas and William H. Murray, III
  Copyright 1998 The McGraw-Hill Companies

OLE Features and Specifications
OLE offers additional features that are not directly related to compound documents. These features specify methods for handling drag-and-drop, data transfer, file management, and so on. This section contains an overview of these concepts.
Objects
Procedure-oriented Windows programming makes extensive use of API function calls. Sometimes it is difficult to see the implementation language (C or C++) because these applications seem to contain nothing but function calls!
In Chapters 22 and 23 you observed a movement away from a procedure-oriented programming approach and toward an object-oriented approach. The MFC library provides the tools for this transition. With OLE, additional tools for object-oriented programming have become available.
The object-oriented component object model is a binary specification or standard that allows two unrelated applications to communicate with each other. The communication takes place through interfaces implemented on the object. When an object conforms to this standard, it is called a Component Object Model or COM object.
A component object can be instantiated through a component object library—which contains functions that support this instantiation. A component object is a Windows object with a unique class ID. The object’s functions, contained in the library and referred to as an interface, can be called via a returned pointer. This process allows the creation of objects that are not dependent upon the programming language. The library also marshals how function calls and function parameters are handled between processes.
Files
OLE allows the use of stream and storage objects—compound files—that streamline file manipulation. The stream object most closely resembles a single file, and the storage object resembles a file directory. This structured storage concept shields you from the actual location of data on a disk.
Microsoft’s long-range plans include the development of a common file structure so that all files can be easily browsed.
Data
Uniform data transfers are made through a data object. OLE uses pointers to a data object. This helps connect the data source to the data receiver. The data object, in turn, handles how data is actually exchanged. Thus, to the programmer, data transfers that use the Clipboard will be handled in the same manner as those that use drag-and-drop.
Embedding
Compound documents can hold information from a variety of unrelated sources. For example, a Microsoft Word document can contain an Excel chart and a Paint bitmap.
Before OLE, items such as charts and bitmaps could be copied to other documents via the Clipboard. Once the objects were “pasted” into the receiving document, they retained no knowledge of their former life. They were static, dead images. If changes eventually had to be made to these objects, the user had to return to the application that originally generated the object, make the changes on the original, and go through the cut-and-paste transfer process once again.
In this case, the Word document would be called the container, and Excel and Paint would be called the servers. A container holds an object or objects created by other applications, whereas a server is the source of an object or objects used by other applications.
An Embedded Object
As an example, this section will teach you how to embed a Paint object into a Microsoft Word document. Word will be the container, and Paint will be the server.
Open Microsoft Word. Figure 25-1 shows a typical Word screen with a small amount of text written in the window.
Figure 25-1: A Microsoft Word application that will serve as a container
From the Microsoft Word Insert menu, select the Object... menu item, as shown in Figure 25-2.
Figure 25-2: Use the insert menu to select the Object… menu item
Once the menu item is selected, the Object dialog box will appear, as shown in Figure 25-3.
Figure 25-3: The Object dialog box allows the type of object to be identified
From the Object dialog box, choose Paintbrush Picture as the object to embed. Paint will be opened automatically, as shown in Figure 25-4, and the drawing surface will float over the top of the Word document. You will now be in the Page Layout view mode of Word.
Figure 25-4: Paint has been identified as the object to be embedded in the Word document
The next step is to use Paint to draw the object that you wish to embed in the Word document. In this example, a little text and several simple graphics shapes were drawn in the Paint drawing area, as shown in Figure 25-5.
Figure 25-5: The graphics to be embedded are completed in paint
Figure 25-6: A new object is saved while within the Paint application
When you are done creating the object, select the Save menu item in Paint’s File menu.
Now click on the Word document to return to Microsoft Word and close the Paint application. Figure 25-7 shows the Word document containing the embedded object while in the Page Layout mode.
Figure 25-7: A Word document with an embedded Paint object
Now, here is the magic. Suppose you decide that the object isn’t exactly what you wanted. Because the transfer is OLE compliant, you can simply single-click on the object to block it for editing, as shown in Figure 25-8.
Figure 25-8: Embedded obiects can be changed by blocking the object
When the object is selected in Word by double-clicking on the object, Paint is immediately opened again with the currently selected object ready for editing. Figure 25-9 shows this process.
Figure 25-9: Blocked objects can easily be changed
Linking
OLE supports a dynamic linking process between applications. When applications are linked, data can be shared instantaneously between the applications. In the past, linking was difficult because it was too easy for users to break the links. With OLE, file monikers prevent most of the link breakage problems. File monikers, based on a path in the file system, are used to identify COM objects that are saved in their own files.

Books24x7.com, Inc 2000 –  


Visual C++ 6(c) The Complete Reference
Visual Studio 6: The Complete Reference
ISBN: B00007FYGA
EAN: N/A
Year: 1998
Pages: 207

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net