📄 ch13.htm
字号:
<HTML>
<HEAD>
<TITLE>Special Edition Using Visual C++ 5 - Chapter 13</TITLE>
<LINK REL="Next" HREF="ch14.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/ch14.htm">
<LINK REL="Previous" HREF="ch12.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/ch12.htm"></HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H2><B>Chapter 13</B></H2>
<H2><B>ActiveX Concepts</B></H2>
<hr>
<P>This chapter covers the theory and concepts of ActiveX, which is built on the Component Object Model (COM). Until recently, the technology built on COM was called OLE, and OLE still exists, but the emphasis now is on ActiveX. Most new programmers have
found OLE intimidating, and the switch to ActiveX is unlikely to lessen that. However, if you think of ActiveX technology as a way to use code already written and tested by someone else, and to save yourself the trouble of reinventing the wheel, you'll see
why it's worth learning. Developer Studio and MFC make ActiveX much easier to understand and implement by doing much of the ground work for you. There are five chapters in Part V, “ActiveX Applications and ActiveX Controls,” and together they
demonstrate what ActiveX has become.</P>
<ul>
<li> <B>What ActiveX is for</B></P>
<P>ActiveX represents the future of Windows and the future of software development according to Microsoft.</P>
<li> <B>Object linking</B></P>
<P>ActiveX is a document-focused technology. Linking connects one document to another and enables a user to build a document from parts that were created with a variety of applications.</P>
<li> <B>Object embedding</B></P>
<P>Embedding one document within another creates a compound document. Each portion of the document is accessed with its own application.</P>
<li> <B>Containers, servers, and why you would write one</B></P>
<P>ActiveX containers can contain embedded objects. ActiveX servers handle the editing of an object that is linked or embedded within another document.</P>
<li> <B>Drag and drop</B></P>
<P>One of the features many users find so intuitive about Windows today is the ability to click on an object, and then, holding the mouse button down, drag the object to another folder or application. Adding this feature to your application will
dramatically increase its usability.</P>
<li> <B>What ActiveX is built on</B></P>
<P>The Component Object Model, or COM, is the technology that makes ActiveX work. Getting your applications to use other applications to perform some of their work makes development easier and faster.</P>
<li> <B>ActiveX automation</B></P>
<P>Do your users need to write scripts or macros for your application? Using ActiveX automation makes it easy for you to add this power to your programs, and saves your users from learning a new macro language too.</P>
<li> <B>ActiveX controls</B></P>
<P>The smallest of all ActiveX components, controls can liven up your application and improve your user interface, or tackle incredibly difficult chores. The growing market in third-party controls could save you weeks or months of coding effort.</P>
</ul>
<H3><B>The Purpose of ActiveX</B></H3>
<P>Windows has always been a way to have several applications running at once, and right from the beginning programmers wanted to have a way for those applications to exchange information while running. The Clipboard was a marvelous innovation, though, of
course, the user had to do a lot of the work. DDE (Dynamic Data Exchange) allowed applications to "talk" to each other but had some major limitations. Then came OLE 1 (Object Linking and Embedding). Later there was OLE 2, then Microsoft just
called it OLE, until it moved so far beyond its original roots that it was renamed ActiveX.</P>
<blockquote><p><img src="note.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/note.gif">
<P>Experienced Windows users will probably be familiar with the examples presented in the early part of this chapter. If you know what ActiveX can do for users, and are interested in why it works, jump ahead to the "Component Object Model"
section, which looks under the hood a little.</P>
<p><img src="bottom.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/bottom.gif"></blockquote>
<P>ActiveX lets users and applications be document-centered, and this is probably the most important thing about it. If a user wants to create an annual report, by choosing ActiveX-enabled applications, the user stays focused on that annual report.
Perhaps parts of it are being done with Word and parts with Excel, but, to the user, these applications are not really the point. This shift in focus is happening on many fronts, and corresponds to a more object-oriented way of thinking among many
programmers. It seems more natural now to share work among several different applications and arrange for them to communicate, than to write one huge application that can do everything.</P>
<P>Here's a simple test to see whether you are document-centered or application-centered: How is your hard drive organized?</P>
<P>The directory structure in Figure 13.1 is application-centered: the directories are named for the applications that were used to create the documents they hold. All Word documents are together, even though they may be for very different clients or
projects.</P>
<A HREF="Ofigs01.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch13/Ofigs01.gif"><b>Fig. 13.1</b></A>
<P><I>An application-centered directory structure arranges documents by type.</I></P>
<P>The directory structure in Figure 13.2 is document-centered: the directories are named for the client or project involved. All the sales files are together, even though they can be accessed with a variety of different applications.</P>
<A HREF="Ofigs02.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch13/Ofigs02.gif"><b>Fig. 13.2</b></A>
<P><I>A document-centered directory structure arranges documents by meaning or </I><I>content.</I></P>
<P>If you've been using desktop computers long enough, you remember when using a program involved a program disk and a data disk. Perhaps you remember installing software that demanded to know the data directory where you would keep all the files created
with that product. That was application-centered thinking, and it's fast being supplanted by document-centered thinking.</P>
<P>Why? What's wrong with application-centered thinking? Well, where do you put the documents that are used with two applications equally often? There was a time when each product could read its own file formats and no others. But these days, the lines
between applications are blurring; a document created in one word processor can easily be read into another, a spreadsheet file can be used as a database, and so on. If a client sends you a WordPerfect document, and you don't have WordPerfect, do you make
a \WORDPERFECT\DOCS directory to put it in, or add it to your \MSOFFICE\WORD\DOCS directory, or what? If you have your hard drive arranged in a more document-centered manner, you can just put it in the directory for that client.</P>
<P>The Windows 95 interface, now incorporated into Windows NT, as well, encourages document-centered thinking by having users double-click documents to automatically launch the applications that created them. This isn't new; File Manager has had that
capability for years, but it feels very different to double-click an icon that's just sitting desktop than it does to start an application and then double-click an entry in a list box. More and more it doesn't matter just what application or applications
were involved in creating this document; you just want to see and change your data, and you want to do that quickly and simply.</P>
<P>After you start being document-centered, you start to see the appeal of compound documents, files created with more than one application. If your report needs an illustration, you create it in some graphic program and then stick it in with your text
when it's done. If your annual report needs a table, and you already have the numbers in a spreadsheet, you don't retype them into the table feature of your word processor, or even import them, you incorporate them as a spreadsheet excerpt, right in the
middle of your text. This isn't earth-shatteringly new, of course. Early desktop publishing programs, such as Ventura, pulled together text and graphics from a variety of sources into one complex compound document. What's new is being able to do it simply,
intuitively, and with so many different applications.</P>
<H3><B>Object Linking</B></H3>
<P>Figure 13.3 shows a Word document with an Excel spreadsheet linked into it.</P>
<A HREF="Ofigs03.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch13/Ofigs03.gif"><b>Fig. 13.3</b></A>
<P><I>A Microsoft Word document can contain a link to an Excel file.</I></P>
<P>Follow these steps to create a similar document yourself:</P>
<ol>
<li><P> Start Word and enter your text.</P>
<li><P> Click where you want the table to go.</P>
<li><P> Choose <U>I</U>nsert, <U>O</U>bject.</P>
<li><P> Select the Create From File tab.</P>
<li><P> Enter or select the file name as though this was a File Open dialog box.</P>
<li><P> Be sure to check the Lin<U>k</U> to File box.</P>
<li><P> Click OK.</P>
</ol>
<P>The entire file appears in your document. If you make a change in the file on disk, the change is reflected in your document. You can edit the file in its own application by double-clicking it within Word. The other application is launched to edit it,
as shown in Figure 13.4. If you delete the file from disk, your Word document still displays what the file last looked like, but you are not able to edit it.</P>
<A HREF="Ofigs04.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch13/Ofigs04.gif"><b>Fig. 13.4</b></A>
<P><I>Double-clicking a linked object launches the application that created </I><I>it.</I></P>
<P>You link files into your documents if you plan to use the same file in many documents and contexts, because your changes to that file are automatically reflected everywhere that you have linked it. Linking doesn't increase the size of your document
files dramatically, since only the location of the file and a little bit of presentation information needs to be kept in your document.</P>
<H3><B>Object Embedding</B></H3>
<P>Embedding is similar to linking, but a copy of the object is made and placed into your document. If you change the original, the changes are not reflected in your document. You can't tell by looking whether the Excel chart you see in your Word document
is linked or embedded. Figure 13.5 shows a spreadsheet embedded within a Word document.</P>
<A HREF="Ofigs05.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch13/Ofigs05.gif"><b>Fig. 13.5</b></A>
<P><I>A file embedded within another file looks just like a linked file.</I></P>
<P>Follow these steps to create a similar document yourself:</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -