📄 vcg10.htm
字号:
<HTML>
<HEAD>
<TITLE>vcg10.htm </TITLE>
<LINK REL="ToC" HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/index.htm">
<LINK REL="Index" HREF="htindex.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/htindex.htm">
<LINK REL="Next" HREF="vcg11.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg11.htm">
<LINK REL="Previous" HREF="vcg09.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg09.htm"></HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<A NAME="I0"></A><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="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>
<HR ALIGN=CENTER>
<P>
<UL>
<UL>
<UL>
<LI>
<A HREF="#E68E59" >The Control Development Kit</A>
<LI>
<A HREF="#E68E60" >A Few OLE Definitions</A>
<UL>
<LI>
<A HREF="#E69E167" >OLE</A>
<LI>
<A HREF="#E69E168" >Objects</A>
<LI>
<A HREF="#E69E169" >Containers</A>
<LI>
<A HREF="#E69E170" >Linked Objects</A>
<LI>
<A HREF="#E69E171" >Embedded Objects</A>
<LI>
<A HREF="#E69E172" >Windows Objects</A>
<LI>
<A HREF="#E69E173" >Automation Servers</A>
<LI>
<A HREF="#E69E174" >Events</A>
<LI>
<A HREF="#E69E175" >Servers</A></UL>
<LI>
<A HREF="#E68E61" >The Relationship Between Servers, Documents, and Containers</A>
<LI>
<A HREF="#E68E62" >What Are OLE Controls?</A>
<LI>
<A HREF="#E68E63" >Using OLE Controls in a Database Application</A>
<UL>
<LI>
<A HREF="#E69E176" >Applications from Microsoft</A></UL>
<LI>
<A HREF="#E68E64" >Summary</A></UL></UL></UL>
<HR ALIGN=CENTER>
<A NAME="E66E27"></A>
<H1 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>- 10 -</B>
<BR><B>Creating Your Own Data Access Controls</B></FONT></CENTER></H1>
<BR>
<P>When OLE Custom Controls were first introduced, they were offered as a separate Software Development Kit (SDK). With current versions of Windows, and as of Visual C++ 2.0, Microsoft has added OLE Custom Controls to Windows and Visual C++. Visual C++ 4 offers built-in support for OLE controls and support for OLE control container applications. A custom OLE control AppWizard helps programmers develop OLE controls. Figure 10.1 shows Visual C++ 4's AppWizard, where the OLE ControlWizard is selected.
<BR>
<P><B><A HREF="10vcg01.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/10vcg01.gif">Figure 10.1. Visual C++ 4's AppWizard creating an OLE control using the OLE ControlWizard.</A></B>
<BR>
<P>This means that now there is one less development tool that you, the programmer, must integrate by hand. Using Visual C++ 4's OLE controls AppWizard lets you create an OLE control without using any external products or features.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE><B>NOTE</B>
<BR>
<BR>Versions of Visual C++ prior to version 4 don't offer integrated OLE control development. You must use the OLE control SDK (called the Control Development Kit, or CDK) with these earlier versions of Visual C++. Though developing OLE controls with versions of Visual C++ earlier than version 4 is possible, it will be easier if you upgrade to Visual C++ 4 if you intend to develop OLE controls. Also, Visual C++ 4 (and Visual Basic 4) let you place OLE controls on the Resource Palette and, from there, place them on your forms. In previous versions, you had to hand-code the interface between the OLE control and your application. Another good reason to upgrade to Visual C++ 4!</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>When using the OLE controls CDK to develop 16-bit controls, you must use Visual C++ 1.5.01 or later, which includes some fixes and changes to the Visual Workbench and ClassWizard to facilitate developing OLE Custom Controls.
<BR>
<P>Where has the "2" in "OLE-2" gone? Microsoft has announced its intention to change OLE's name from OLE-2 to just OLE. This change was made to allow Microsoft to expand OLE without changing the name, meaning that there will never be an OLE-3 or OLE-4.
<BR>
<P>This chapter covers the basics of OLE Custom Controls. The specifics of OLE Custom Controls and their use in database development will be discussed in later chapters.
<BR>
<P>The term <I>OLE Custom Controls</I> is a mouthful. Some publications use the term OCX for OLE Custom Controls (OCX is the accepted extension for an OLE control), but this book uses the term <I>OLE controls,</I> which is what Microsoft uses. The OLE Custom Controls Development Kit is referred to as the CDK when referring to Visual C++ 1.5x and 2.x. Visual C++ 4 doesn't have a separate CDK component.
<BR>
<P><B>WARNING</B>
<BR>
<BR>It's possible to have some rather nasty accidents when you're using applications that work with the registration database. On more than one occasion, I've destroyed the registration database, and the results are nothing short of awful. Some versions of Windows will refuse to run; others will run, but not well; and still others will never notice the loss of the registration database.
<BR>
<BR>Make sure that you have a backup of your current registration database. Many versions of RegEdit, the utility that is used to make manual modifications to the registration database, also export the registration database. For Windows 3.x, the file is REG.DAT. For Windows 95, back up the SYSTEM.DA? and USER.DA? files. Some of these files might have the hidden attribute and therefore won't be visible unless you use the command DIR /AH. Windows NT has a similar set of database files to store the registry. You can look in \WINNT\SYSTEM32\CONFIG and back up all the files in this directory.
<BR>
<BR>This information is also backed up when you create your emergency recovery disks for Windows 95 and Windows NT. But these disks will only cover the registry as it existed when you first installed your operating system. Any changes made by applications you installed later would be lost.
<BR>
<BR>Remember: Back it up or lose it. Generally, losing the registration database means reinstalling Windows and many (if not all) of your Windows applications.
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE><B>NOTE</B>
<BR>
<BR>Microsoft has included a utility called CFGBACK that can be used to back up the registry under Windows 95. Also, the utility ERU can be used to back up all critical files that are part of your Windows 95 system (CFGBACK backs up only the registry). The user would run these utilities before making changes, such as adding new software or hardware, or any time he wanted to make a backup copy of his configuration.
<BR>
<BR>The CFGBACK utility can be found on the Windows 95 CD in the directory \OTHER\MISC\CFGBACK. It's also included as part of the Windows 95 Resource Kit. The ERU utility can be found in \OTHER\MISC\ERU, but it's not part of the Windows 95 Resource Kit. Both of these utilities are documented with .TXT files.
<BR>
<BR>The backup created with the ERU utility is restored using the ERD utility—ERD.E_E. You must copy it to a directory on a writeable disk and rename it ERD.EXE in order to use it.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E68E59"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>The Control Development Kit</B></FONT></CENTER></H3>
<BR>
<P>The OLE Control Development Kit was a separate component of the Visual C++ 2.0 system. However, with Visual C++ 4, OLE control support is built-in and has no installable components. The following features moved from add-ons in version 2 to built-ins in version 4:
<BR>
<UL>
<LI>ControlWizard: This is a new support wizard that works much like AppWizard. You can create a new control easily because the wizard writes the control's shell for you.
<BR>
<BR>
<LI>ClassWizard: For Visual C++, the CDK installs a new ClassWizard that offers the necessary support for OLE controls.
<BR>
<BR>
<LI>MFC: The CDK adds new classes to MFC to support OLE controls.
<BR>
<BR>
<LI>Sample code: The CDK includes a number of sample controls that you can work with to learn some of the OLE control programming techniques.
<BR>
<BR>
<LI>CDK Books Online: The CDK adds a new help file, CDK Books OnLine, that lets you easily look up information on OLE controls.
<BR>
<BR>
<LI>Test Container: You can use this program to test your newly developed OLE controls. This program lets you test all of a new control's functionality.
<BR>
<BR>
</UL>
<P>Many of the new tools used to create OLE controls appear on the Visual Workbench Tools menu:
<BR>
<UL>
<LI>ControlWizard is the equivalent of AppWizard for controls.
<BR>
<BR>
<LI>Register Control lets you register your OLE control in the system registry.
<BR>
<BR>
<LI>Unregister Control is used to remove your OLE control from the registry.
<BR>
<BR>
<LI>Test Container lets you test your newly developed OLE control. It also offers the capability to test all of an OLE control's features.
<BR>
<BR>
<LI>WPS (installed only under 16-bit environments) is a thread/process monitoring utility that lets you kill a thread or process if necessary. This utility isn't installed with Visual C++ 2.0. or later. However, Windows 95 users might find it useful because it performs many of the same tasks as the PStat (process status) and PView (process view) utilities, which don't run under Windows 95.
<BR>
<BR>
</UL>
<P>In Visual C++ 4, these functionalities are built into the IDE. This makes developing OLE controls simpler and alleviates the need to do many mundane tasks by hand. Visual C++ 4 has the following functionalities:
<BR>
<UL>
<LI>ClassWizard: With Visual C++ 4, ClassWizard includes extensive OLE support. Included are tabs for OLE Automation and OLE Events, as shown in Figure 10.2.
<BR>
<BR>
</UL>
<P><B><A HREF="10vcg02.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/10vcg02.gif">Figure 10.2. Visual C++ 4's ClassWizard, showing the OLE Automation tab.</A></B>
<BR>
<UL>
<LI>AppWizard: A new project type, OLE ControlWizard, allows direct building of OLE controls.
<BR>
<BR>
<LI>MFC: MFC 4 gives you an excellent set of OLE supporting classes.
<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -