?? ch13.htm
字號:
<P><A HREF="javascript:popUp('13uvc03.gif')"><B>FIG. 13.3</B></A><B> </B><I>A Microsoft
Word document can contain a link to an Excel file.</I></P>
<P><A HREF="javascript:popUp('13uvc04.gif')"><B>FIG. 13.4</B></A><B> </B><I>Double-clicking
a linked object launches the application that created 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 because only the location of the file and a little bit of presentation
information needs to be kept in your document.</P>
<P>
<H2><A NAME="Heading3"></A>Object Embedding</H2>
<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 aren't 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>
<P><A HREF="javascript:popUp('13uvc05.gif')"><B>FIG. 13.5</B></A><B> </B><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>
<P>
<DL>
<DD><B>1. </B>Start Word and enter your text.
<P>
<DT></DT>
<DD><B>2. </B>Click where you want the table to go.
<P>
<DT></DT>
<DD><B>3. </B>Choose Insert, Object.
<P>
<DT></DT>
<DD><B>4. </B>Select the Create from File tab.
<P>
<DT></DT>
<DD><B>5. </B>Enter or select the filename as though this were a File Open dialog
box.
<P>
<DT></DT>
<DD><B>6. </B>Do not check the Link to File box.
<P>
<DT></DT>
<DD><B>7.</B> Click OK.
<P>
</DL>
<P>What's the difference? You'll see when you double-click the object to edit it.
The Word menus and toolbars disappear and are replaced with their Excel equivalents,
as shown in Figure 13.6. Changes you make here aren't made in the file you originally
embedded. They are made in the copy of that file that has become part of your Word
document.</P>
<P><A HREF="javascript:popUp('13uvc06.gif')"><B>FIG. 13.6</B></A><B> </B><I>Editing
in place is the magic of OLE embedding.</I></P>
<P>You embed files into your documents if you plan to build a compound document and
then use it as a self-contained whole, without using the individual parts again.
Changes you make don't affect any other files on your disk, not even the one you
copied from in the first place. Embedding makes your document much larger than it
was, but you can delete the original if space is a problem.</P>
<P>
<H2><A NAME="Heading4"></A>Containers and Servers</H2>
<P>To embed or link one object into another, you need a <I>container</I> and a <I>server</I>.
The container is the application into which the object is linked or embedded--Word
in these examples. The server is the application that made them, and that can be
launched (perhaps in place) when the object is double-clicked--Excel in these examples.</P>
<P>Why would you develop a container application? To save yourself work. Imagine
you have a product already developed and in the hands of your users. It does a specific
task like organize a sales team, schedule games in a league sport, or calculate life
insurance rates. Then your users tell you that they wish it had a spreadsheet capability
so they could do small calculations on-the-fly. How long will it take you to add
that functionality? Do you really have time to learn how spreadsheet programs parse
the functions that users type?</P>
<P>If your application is a container app, it doesn't take any time at all. Tell
your users to link or embed in an Excel sheet and let Excel do the work. If they
don't own a copy of Excel, they need some spreadsheet application that can be an
ActiveX server. You get to piggyback on the effort of other developers.</P>
<P>It's not just spreadsheets, either. What if users want a scratch pad, a place
to scribble a few notes? Let them embed a Word document. (What about bitmaps and
other illustrations? Microsoft Paint, or a more powerful graphics package if they
have one, and it can act as an ActiveX server.) You don't have to concern yourself
with adding functionality like this to your programs because you can just make your
application a container and your users can embed whatever they want without any more
work on your part.</P>
<P>Why would you develop a server application, then? Look back over the reasons for
writing a container application. A lot of users are going to contact developers asking
for a feature to be added, and be told they can have that feature immediately--they
just need an application that does spreadsheets, text, pictures, or whatever, and
can act as an ActiveX server. If your application is an ActiveX server, people will
buy it so that they can add its functionality to their container apps.</P>
<P>Together, container and server apps enable users to build the documents they want.
They represent a move toward building-block software and a document-centered approach
to work. If you want your application to carry the Windows 95 logo, it must be a
server, a container, or both. But there is much more to ActiveX than linking and
embedding.</P>
<P>
<H2><A NAME="Heading5"></A>Toward a More Intuitive User Interface</H2>
<P>What if the object you want to embed is not in a file but is part of a document
you have open at the moment? You may have already discovered that you can use the
Clipboard to transfer ActiveX objects. For example, to embed part of an Excel spreadsheet
into a Word document, you can follow these steps:</P>
<P>
<DL>
<DD><B>1. </B>Open the spreadsheet in Excel.
<P>
<DT></DT>
<DD><B>2. </B>Open the document in Word.
<P>
<DT></DT>
<DD><B>3. </B>In Excel, select the portion you want to copy.
<P>
<DT></DT>
<DD><B>4. </B>Choose Edit, Copy to copy the block onto the Clipboard.
<P>
<DT></DT>
<DD><B>5. </B>Switch to Word and choose Edit, Paste Special.
<P>
<DT></DT>
<DD><B>6. </B>Select the Paste radio button.
<P>
<DT></DT>
<DD><B>7. </B>Select Microsoft Excel Worksheet Object from the list box.
<P>
<DT></DT>
<DD><B>8. </B>Make sure that Display as Icon is not selected.
<P>
<DT></DT>
<DD><B>9.</B> The dialog box should look like Figure 13.7. Click OK.
</DL>
<P>A copy of the block is now embedded into the document. If you choose Paste Link,
changes in the spreadsheet are reflected immediately in the Word document, not just
when you save them. (You might have to click the selection in Word to update it.)
This is true even if the spreadsheet has no name and has never been saved. Try it
yourself! This is certainly better than saving dummy files just to embed them into
compound documents and then deleting them, isn't it?</P>
<P><A HREF="javascript:popUp('13uvc07.gif')"><B>FIG. 13.7</B></A><B> </B><I>The Paste
Special dialog box is used to link or embed selected portions of a document.</I></P>
<P>Another way to embed part of a document into another is drag and drop. This is
a user- interface paradigm that works in a variety of contexts. You click something
(an icon, a highlighted block of text, a selection in a list box) and hold the mouse
button down while moving it. The item you clicked moves with the mouse, and when
you let go of the mouse button, it drops to the new location. That's very intuitive
for moving or resizing windows, but now you can use it to do much, much more. For
example, here's how that Excel-in-Word example would be done with drag and drop:</P>
<P>
<DL>
<DD><B>1. </B>Open Word and size it to less than full screen.
<P>
<DT></DT>
<DD><B>2. </B>Open Excel and size it to less than full screen. If you can arrange
the Word and Excel windows so they don't overlap, that's great.
<P>
<DT></DT>
<DD><B>3. </B>In Excel, select the portion you want to copy by highlighting it with
the mouse or cursor keys.
<P>
<DT></DT>
<DD><B>4. </B>Click the border of the selected area (the thick black line) and hold.
<P>
<DT></DT>
<DD><B>5. </B>Drag the block into the Word window and let go.
<P>
</DL>
<P>The selected block is embedded into the Word document. If you double-click it,
you are editing in place with Excel. Drag and drop also works within a document to
move or copy a selection.</P>
<BLOCKQUOTE>
<P>
<HR>
<strong>TIP:</strong> The block is moved by default, which means it is deleted from the
Excel sheet. If you want a copy, hold down the Ctrl key while dragging, and release
the mouse button before the Ctrl key.
<HR>
</BLOCKQUOTE>
<P>You can also use drag and drop with icons. On your desktop, if you drag a file
to a folder, it is moved there. (Hold down Ctrl while dragging to copy it.) If you
drag it to a program icon, it is opened with that program. This is very useful when
you have a document you use with two applications. For example, pages on the World
Wide Web are HTML documents, often created with an HTML editor but viewed with a
World Wide Web browser such as Netscape Navigator or Microsoft Internet Explorer.
If you double-click an HTML document icon, your browser is launched to view it. If
you drag that icon onto the icon for your HTML editor, the editor is launched and
opens the file you dragged. After you realize you can do this, you will find your
work speeds up dramatically.</P>
<P>All of this is ActiveX, and all of this requires a little bit of work from programmers
to make it happen. So what's going on?</P>
<P>
<H2><A NAME="Heading6"></A>The Component Object Model</H2>
<P>The heart of ActiveX is the Component Object Model (COM). This is an incredibly
complex topic that deserves a book of its own. Luckily, the Microsoft Foundation
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -