📄 vcg16.htm
字号:
<HTML>
<HEAD>
<TITLE>vcg16.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="vcg17.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg17.htm">
<LINK REL="Previous" HREF="vcg15.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg15.htm"></HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<A NAME="I0"></A><P ALIGN=CENTER>
<A HREF="vcg15.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg15.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="vcg17.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcg17.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="#E68E83" >OLE Control Development Tools</A>
<UL>
<LI>
<A HREF="#E69E212" >ControlWizard</A>
<UL>
<LI>
<A HREF="#E70E80" >OLE ControlWizard's Step 1 of 2 Dialog Box</A>
<LI>
<A HREF="#E70E81" >OLE ControlWizard's Step 2 of 2 Dialog Box</A>
<LI>
<A HREF="#E70E82" >The Edit Names Dialog Box</A>
<LI>
<A HREF="#E70E83" >Generating Your OLE Control</A></UL>
<LI>
<A HREF="#E69E213" >Register/Unregister Control</A>
<LI>
<A HREF="#E69E214" >Test Container</A>
<LI>
<A HREF="#E69E215" >WPS</A>
<LI>
<A HREF="#E69E216" >PView95</A>
<LI>
<A HREF="#E69E217" >Make TypeLib</A></UL>
<LI>
<A HREF="#E68E84" >Creating an OLE Control</A>
<UL>
<LI>
<A HREF="#E69E218" >Creating an OLE Control Shell</A>
<LI>
<A HREF="#E69E219" >Adding Properties to an OLE Control</A>
<UL>
<LI>
<A HREF="#E70E84" >Stock Properties: Colors</A>
<LI>
<A HREF="#E70E85" >Adding Functionality to the Clock Control</A>
<LI>
<A HREF="#E70E86" >More Stock Properties: Fonts</A>
<LI>
<A HREF="#E70E87" >Custom Properties</A></UL>
<LI>
<A HREF="#E69E220" >Adding Events to an OLE Control</A>
<UL>
<LI>
<A HREF="#E70E88" >Stock Events</A>
<LI>
<A HREF="#E70E89" >Custom Events</A></UL>
<LI>
<A HREF="#E69E221" >Adding Methods to an OLE Control</A>
<UL>
<LI>
<A HREF="#E70E90" >Adding a Stock Method</A>
<LI>
<A HREF="#E70E91" >Adding a Custom Method</A></UL>
<LI>
<A HREF="#E69E222" >Interfacing with the Clock OLE Control from a Visual C++ 4 Application</A>
<LI>
<A HREF="#E69E223" >A Few More Bells and Whistles</A>
<LI>
<A HREF="#E69E224" >License Validation</A>
<UL>
<LI>
<A HREF="#E70E92" >Adding License Validation to a New Control</A>
<LI>
<A HREF="#E70E93" >Adding License Validation to Clock</A></UL>
<LI>
<A HREF="#E69E225" >Using Your OLE Control Outside Visual C++ Programs</A>
<LI>
<A HREF="#E69E226" >Shipping Your OLE Control</A></UL>
<LI>
<A HREF="#E68E85" >Summary</A></UL></UL></UL>
<HR ALIGN=CENTER>
<A NAME="E66E41"></A>
<H1 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>- 16 -</B>
<BR><B>Creating OLE Controls with Visual C++ 4</B></FONT></CENTER></H1>
<BR>
<P>This chapter describes the development of OLE controls and is divided into two parts. The first part covers the OLE control development tools that Visual C++ offers the database programmer, and the second part takes you through the process of creating your own OLE control.
<BR>
<P>This book isn't about writing OLE controls. One or two chapters can't cover everything you need to know about writing (or using) OLE controls. If you're thinking about developing OLE controls, you should consider a book oriented toward OLE controls. (The next chapter teaches you how to use OLE controls, something that most database programmers will find useful.)
<BR>
<P>This chapter doesn't take into consideration who you're developing an OLE control for. You could be developing OLE controls for your own internal use, for others in your company or organization, or for sale to other programmers. There will be a large market for OLE controls in the future. This could be a field that smart programmers could exploit to their advantage.
<BR>
<BR>
<A NAME="E68E83"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>OLE Control Development Tools</B></FONT></CENTER></H3>
<BR>
<P>Supplied with Visual C++ 1.5x and Visual C++ 2.x is a separate development kit called the OLE Controls Development Kit (CDK). This facility is integrated into Visual C++ 4, making Visual C++ 4 an easier-to-use system. Since it can be assumed that some developers will have to develop 16-bit OLE controls using Visual C++ 1.5x (which is included with Visual C++ 4), I've included some information about the CDK and other related tools in this chapter.
<BR>
<P>This section describes the development tools that are supplied with the OLE control CDK and are built into Visual C++ 4. These tools make the process of developing OLE controls easy and (hopefully) painless, and they vary depending on the platform under which you're developing. For instance, the Make TypeLib (MKTYPLIB) utility isn't called by the programmer directly, except when you're using 16-bit versions of Visual C++. Visual C++ 2's WPS (Windows Process Status) utility, used to view process threads (specifically, to see what DLLs are loaded), isn't used under Windows NT because the PStat and PView utilities are part of the Visual C++ 2.0 package. With Visual C++ 4, the Windows NT system has both PView and PStat, neither of which can be used under Windows 95. The PView95 program is available for Windows 95 users of Visual C++ 4. It can be found on the Visual C++ 4 CD in the directory \MSDEV\BIN\WIN95.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE><B>CAUTION</B>
<BR>
<BR>When you're converting OLE controls created with the CDK supplied with Visual C++ 1.5x and 2.x, you should read the topic <I>OLE Controls: Converting a CDK Project to a </I><I>Visual C++ Project</I> in the <I>Programming with MFC </I><I>Encyclopedia,</I> which is part of the Visual C++ Books Online documentation.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>Unless otherwise noted, the descriptions of the tools in this chapter are for how they run under Visual C++ 4. When a tool works significantly differently under other versions of Visual C++ (including the 16-bit version, 1.5x), the differences are noted.
<BR>
<BR>
<A NAME="E69E212"></A>
<H4 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>ControlWizard</B></FONT></CENTER></H4>
<BR>
<P>This section introduces you to ControlWizard. You use ControlWizard to develop the shell for your OLE controls. Its user interface looks and feels very much like that of AppWizard in Visual C++, because it's an integrated AppWizard in Visual C++ 4. This is a major improvement to earlier versions of Visual C++, in which ControlWizard was a separate application, external to Visual C++'s Developer Studio.
<BR>
<P>To create a new OLE control, you first start App Wizard and select an OLE control project type, as shown in Figure 16.1. This figure shows that an OLE control is being created; the name for the control has been entered. After it's started, AppWizard's ControlWizard displays the main dialog box, shown in Figure 16.2.
<BR>
<P><B><A HREF="16vcg01.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/16vcg01.gif">Figure 16.1. AppWizard showing the OLE control project type.</A></B>
<BR>
<P><B><A HREF="16vcg02.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/16vcg02.gif">Figure 16.2. ControlWizard's Step 1 of 2 dialog box.</A></B>
<BR>
<P>Before you name the new OLE control, you must select the directory in which the new control will be created. When you specify the control's name, that name is used to create the control's subdirectory. If you like, either before or after specifying the control's name, you can change the path to the project's directory.
<BR>
<P>After you name your new control and specify its location, you can specify its options and configuration. These options and configurations are grouped using two Wizard dialogs. The first is shown in Figure 16.2, and the second is shown in Figure 16.3. These Wizard dialogs are described in the following sections.
<BR>
<P><B><A HREF="16vcg03.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/16vcg03.gif">Figure 16.3. ControlWizard's Step 2 of 2 dialog box.</A></B>
<BR>
<BR>
<A NAME="E70E80"></A>
<H5 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>OLE ControlWizard's Step 1 of 2 Dialog Box</B></FONT></CENTER></H5>
<BR>
<P>The following options are available in OLE ControlWizard's first step:
<BR>
<UL>
<LI>You can set the number of controls that you will have in this project at development time. You can modify this number later if you want. However, if you know that your project will have more than one control, you should specify the number of OLE controls at this time. The default is to have one control in a project.
<BR>
<BR>
<LI>The runtime license validation option, which normally isn't selected, tells ControlWizard to add calls to enforce licensing and to create a .LIC license file for your control. You can later modify both the validation code and the .LIC file as desired.
<BR>
<BR>
<LI>The generation of source comments can be specified. Usually selected, this option tells ControlWizard to create comments in the source and header files to assist you in adding and modifying the code created.
<BR>
<BR>
<LI>Help files can be created automatically for your OLE control project. Generally, a control that you will distribute should be documented, while a control that will be used only by you can be documented in the control's code. The default is to not create a help file for the control.
<BR>
<BR>
</UL>
<P>As soon as you've set the desired options for the first step in ControlWizard, you can move to the second step.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE><B>NOTE</B>
<BR>
<BR>Remember when using ControlWizard that you can go back and change settings made in previous steps. You aren't locked into any choice until you actually create your project. You can even back up to the initial selection of the project's name and location if you want to.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E70E81"></A>
<H5 ALIGN=CENTER>
<CENTER>
<FONT SIZE=4 COLOR="#FF0000"><B>OLE ControlWizard's Step 2 of 2 Dialog Box</B></FONT></CENTER></H5>
<BR>
<P>The following options are available in OLE ControlWizard's second and final step. Each control in the project may have different options that can be set in the second step. Also, the second step is where you can modify the names for your project's controls.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE><B>NOTE</B>
<BR>
<BR>Regardless of the number of controls in a project, you can rename the controls at the second step. A control's name doesn't have to be the project's name, for example.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<P>Each of the options in the second step is associated with a specific control. That way, you can have controls with different attributes in the same project. The following options may be set for each control.
<BR>
<UL>
<LI>The Activate when visible option specifies that when the control is visible, it's active. You would check this box if you wanted to tell the container that the control prefers to be automatically activated when it's visible. Even if you select this option, container applications aren't required to support it.
<BR>
<BR>
<LI>The Invisible at runtime option specifies that the control is visible only when it's in design mode. When in run mode, the control is invisible. (In other words, the user can't see the control when the application is running.) Even if this option is selected, container applications aren't required to support it.
<BR>
<BR>
<LI>The Available in 'Insert Object' dialog option specifies that the control will be listed in the container application's Insert Object dialog box.
<BR>
<BR>
<LI>The Has an 'About' box option specifies that ControlWizard will create a standard About dialog box and AboutBox method for the currently selected control. The About dialog is displayed when the container invokes your control's AboutBox method. You can later customize the About box as desired.
<BR>
<BR>
<LI>The Acts as a simple frame control option specifies that the currently selected control support will be the ISimpleFrameSite protocol. When the control and the container both support this protocol, the container uses simple frame controls as parents for other controls in the container. The result is that the simple frame control will operate as an OLE compound document container, but the frame control's container will do virtually all the work.
<BR>
<BR>
<LI>The Which window class, if any, should this control subclass? option specifies that the control will subclass a common Windows control, such as a button, toolbar, or edit box. Table 16.1 lists the possibilities for this selection.
<BR>
<BR>
</UL>
<BR>
<P ALIGN=CENTER>
<CENTER>
<FONT COLOR="#000080"><B>Table 16.1. Windows controls that an OLE control may subclass.</B></FONT></CENTER>
<BR>
<CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Control</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Description</I>
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
BUTTON
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The standard button control.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
COMBOBOX
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The standard combo-box control.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
EDIT
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The standard edit control (not the RTF edit control).
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
LISTBOX
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The standard list box control.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
mscrls_hotkey32
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The Win32 hot key control.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
mscrls_progress32
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The Win32 progress bar control.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
mscrls_status32
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
The Win32 status control.
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
mscrls_trackbar32
</FONT>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -