⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vcg10.htm

📁 Visual C++与数据库的连接经典实例
💻 HTM
📖 第 1 页 / 共 3 页
字号:

<P>A <I>Windows object</I> is an OLE object that defines at least one interface, IUnknown.

<BR>

<P>Each object must provide a function table for each interface that the object supports. When you use ControlWizard to develop OLE controls, the details of the interface are managed for you.

<BR>

<BR>

<A NAME="E69E173"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Automation Servers</B></FONT></CENTER></H4>

<BR>

<P>An OLE <I>automation server</I> is an application that exposes a programmable object (the server's functionality) to an OLE container application. This exposure is done using the IDispatch interface.

<BR>

<P>For example, a Geographical Information (GIS) program could expose its zip code validator to other applications for their own use. That way, a mail list program (perhaps part of an Access database) could verify that the street, city, state, and zip code portions of an address are correct before printing a mailing label.

<BR>

<BR>

<A NAME="E69E174"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Events</B></FONT></CENTER></H4>

<BR>

<P><I>Events</I> are simply things that happen (a crummy, but accurate, definition). A Windows event could be an action such as a mouse message (movement or clicking), a keyboard action, or perhaps a timer message (as in the digital clock OLE control).

<BR>

<BR>

<A NAME="E69E175"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Servers</B></FONT></CENTER></H4>

<BR>

<P>A <I>server</I> is an application that is the source, or creator, of an object. Even if the preceding sentence says it all, it says nothing. It is simply jargon used to explain more jargon. No wonder Windows programming is getting so complex! The following section will clarify this definition.

<BR>

<BR>

<A NAME="E68E61"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>The Relationship Between Servers, Documents, and Containers</B></FONT></CENTER></H3>

<BR>

<P>Let's try to define a server again. Rather than using computer terms, let's try something else: a company picnic. I've planned the picnic because I want to butter up my boss (the chairman of the board) so that I can ask for a raise.

<BR>

<P>I set up a table, put on a tablecloth, silverware, and napkins, and ask each of my employees to bring something to eat.

<BR>

<P>The company, which is sponsoring the picnic, is the container application. The table is the document. Actually, the table is a compound document, because it has objects on it. (In OLE terminology, the objects would be embedded or linked; however, be careful how you embed a bowl of potato salad in the table. The results might be less than appealing if you embed the bowl too aggressively.)

<BR>

<P>You could place a bowl on the table with a picture of potato salad and a small card inside, telling those who want potato salad that &quot;the potato salad is in the cooler.&quot; This would make the potato salad a linked object because its data (the actual salad) is stored externally to the main document (the picnic table).

<BR>

<P>However, in keeping with picnic tradition, you place an object full of potato salad on the table. Because you brought the potato salad, you are the server, the potato salad is an object, and the table is a compound document. (Please don't say I'm nuts&#151;yet.)

<BR>

<P>When you brought your potato salad, you didn't bring it on a nice plate with the necessary garnishes. You transported it in a plastic Tupperware container. As president of the company, I ask you to present your potato salad, and you do so by putting it on an attractive plate with a little parsley on the side to make it look good. Now that the potato salad is presentable, I put it in the center of the table.

<BR>

<P>It just so happens that the company's chairman of the board (my boss, the person for whom we're having this picnic) has sampled your potato salad. He thinks he knows everything about salads, and he wants to change yours by adding some pepper. My boss (representing the user) tells me (the application) to get you (the server) to make the change. (He couldn't really tell the table; it's just a document.) You comply by adding the pepper, and you put the potato salad back on the table.

<BR>

<P>I figure that having you change your salad would satisfy my boss, but it doesn't. My boss (the user) tells me (the application) that he thinks the salad would look better at the end of the table, so I move it. Because I'm only moving the salad and not changing it, I can do this myself. Of course, each time I move the salad, you step in and adjust the plate so that it looks just right.

<BR>

<P><I>Now</I> you can say I'm nuts, but basically, that's how OLE servers and containers work!

<BR>

<P>Just like the movies, let's give proper OLE credit to the players (cue the music):

<BR>

<UL>

<UL>

<P>The Company: The application (the container).

</UL></UL>

<UL>

<UL>

<P>You: The object's server.

</UL></UL>

<UL>

<UL>

<P>My Boss: The user.

</UL></UL>

<UL>

<UL>

<P>The Potato Salad: The object to be embedded.

</UL></UL>

<BLOCKQUOTE>

<BLOCKQUOTE>

<P>The Table: The compound document.

<BR>

</BLOCKQUOTE></BLOCKQUOTE>

<BR>

<A NAME="E68E62"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>What Are OLE Controls?</B></FONT></CENTER></H3>

<BR>

<P>At this point you are well into the introduction to OLE Controls but you haven't learned about OLE Controls yet. You're probably wondering what an OLE Control is. Microsoft defines an OLE Control as being &quot;implemented as an OLE compound document object with visual editing support. OLE Controls have additional capabilities beyond those of ordinary OLE objects, such as the ability to fire events.&quot;

<BR>

<P>An OLE control is a program that behaves like an object whose working interface with the user is through the OLE control's user area. An OLE control's format or layout generally is fixed, but its contents may vary. For example, a programmer can create an OLE control that looks similar to the standard list box found in many dialog boxes but that includes special properties such as multiple columns.

<BR>

<P>In Chapter <A NAME="I2"></A>16 you will create an OLE control that is a digital clock. In this OLE control, you display the current time in a font and style that the end user can define. In fact, you could use the digital clock control in an Access 95 form or report to display the current time or embed it into a Word document. (However, Word and Excel don't fully support OLE controls in documents, so the actual performance of the OLE control in Word probably will be less than satisfactory.) When an OLE control is embedded into a Word or Excel document, it basically becomes an OLE automation server, which might not be the desired effect.

<BR>

<P>An automation server is an application that exposes a programmable object to another application. OLE controls become automation servers in Word and Excel documents because the current versions of Word and Excel don't support events. <I>Events</I> are responses by an OLE custom control to an outside action on the control, such as a mouse click.

<BR>

<P>One thing to keep in mind is that Microsoft has committed to supporting OLE controls in its database and development tools. Don't be surprised if Microsoft supports OLE controls in future versions of both Word and Excel.

<BR>

<BR>

<A NAME="E68E63"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Using OLE Controls in a Database Application</B></FONT></CENTER></H3>

<BR>

<P>You can use OLE controls in many different applications. OLE controls let a developer interface with other applications such as Microsoft Access. Programmers also can add extensive flexibility using OLE controls in their applications. OLE controls can also add functionality to an existing application. A classic example is adding the OLE control digital clock, which you develop in Chapter 16, to the forms of an Access database program. Another possible OLE control is a calendar that displays the current month, perhaps with buttons to scroll forward and backward. There are many situations in which a person using an Access database might need to know a date or a date's day of the week.

<BR>

<BR>

<A NAME="E69E176"></A>

<H4 ALIGN=CENTER>

<CENTER>

<FONT SIZE=4 COLOR="#FF0000"><B>Applications from Microsoft</B></FONT></CENTER></H4>

<BR>

<P>As this book was being written in late 1995, the only application that fully supported OLE controls was Microsoft Access. This situation is rapidly changing. Visual C++ 4 applications can support OLE controls in dialog boxes. (See the sample programs OLE Container and OLE Control in the CHAPTR10 folder on the CD that comes with this book.) With this new flexibility, we can expect that there will be many, many OLE control-aware applications that will allow the embedding of OLE controls in dialog boxes or even documents. With Microsoft Access, you can place OLE controls in both forms and reports.

<BR>

<P>Access can work with OLE controls that you create, and also with the many aftermarket OLE controls that will be available for Access. Visual C++ 4 comes with a number of useful OLE controls that you can embed into your applications:

<BR>

<UL>

<LI>Anibutton: An OLE control that uses icons, bitmaps, and metafiles.

<BR>

<BR>

<LI>Grid control: Displays a series of rows and columns.

<BR>

<BR>

<LI>Key state control: Returns information about the state of the Caps Lock, Num Lock, Scroll Lock, and Insert keys.

<BR>

<BR>

<LI>Microsoft comm control: Allows access to the serial ports.

<BR>

<BR>

<LI>Microsoft masked edit control: Allows the input and display of data based on a complex edit mask.

<BR>

<BR>

<LI>Microsoft multimedia control: Allows the display of multimedia.

<BR>

<BR>

<LI>PicClip Control: Allows the display of a portion of a bitmap.

<BR>

<BR>

</UL>

<P>Word for Windows and Excel both allow the insertion of OLE controls into documents. However, when an OLE control is subsequently copied to the clipboard, or when the container document is saved, the OLE control ceases to be an OLE control and becomes a standard OLE automation server&#151;with a few minor differences.

<BR>

<P>Another excellent use of OLE controls created with Visual C++ 4 is with Visual Basic 4. Since Visual Basic 4 is also a 32-bit application, it can use all the OLE controls you create with Visual C++ 4.

<BR>

<P>It's still possible to create OLE controls that can be used in containers that don't support OLE controls. What must be taken into consideration is that the control won't receive event notifications (such as mouse actions or certain Windows messages) other than those necessary to manage the embedded control, such as resizing and movement.

<BR>

<BR>

<A NAME="E68E64"></A>

<H3 ALIGN=CENTER>

<CENTER>

<FONT SIZE=5 COLOR="#FF0000"><B>Summary</B></FONT></CENTER></H3>

<BR>

<P>This chapter introduced OLE controls, the CDK for Visual C++ 1.5x and 2.x, and the OLE concepts that make up OLE controls. The following topics were covered:

<BR>

<UL>

<LI>OLE controls, which are OLE compound objects with additional capabilities such as event support

<BR>

<BR>

<LI>CDK, the Control Development Kit

<BR>

<BR>

<LI>Definitions of some of the terms commonly used with OLE controls

<BR>

<BR>

</UL>

<P>In Chapter 16, you will develop an OLE control that can be embedded into any Visual C++ 4 application dialog box.

<P ALIGN=CENTER>

<A HREF="vcg09.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg09.htm" TARGET="_self"><IMG SRC="blanprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blanprev.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="Previous Page"></A>

<A HREF="#I0" TARGET="_self"><IMG SRC="blantop.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blantop.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="Page Top"></A>

<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/index.htm" TARGET="_self"><IMG SRC="blantoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blantoc.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="TOC"></A>

<A HREF="vcg11.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg11.htm" TARGET="_self"><IMG SRC="blannext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blannext.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="Next Page"></A>


</BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -