📄 ch15.htm
字号:
you to easily add controls and create VBScript and JavaScript scripts. It also integrates
a WSIWYG design area for authoring 2-D layouts in conjunction with Microsoft's HTML
Layout Control.</P>
<P>When you first bring up Control Pad, it creates an initial blank HTML document
and opens the document in the Text Editor (see fig. 15.8). <B><BR>
<BR>
</B><A HREF="Art/15/15fig08.jpg"><B>FIG. 15.8</B></A> <BR>
<I>When you first bring up Control Pad, it creates a blank HTML document.</I></P>
<P>To insert an ActiveX Control, select <U>E</U>dit, <U>I</U>nsert ActiveX Control,
which opens the Insert ActiveX Control dialog. This dialog displays a list of all
registered ActiveX controls. Select the control you want to insert from the <U>C</U>ontrol
Type list box on the Insert ActiveX Control dialog, and click the OK button. A form
displaying the control appears along with a Properties grid. Use the mouse to size
the control. <BR>
<BR>
<IMG SRC="bar.gif" WIDTH="480" HEIGHT="6" ALIGN="BOTTOM" BORDER="0"></P>
<BLOCKQUOTE>
<P><B>NOTE:</B> Version 1.0 of the ActiveX Control Pad has some bugs in its refreshing
functionality. Once in a while, items appear to smear when you are sizing or positioning
them, but they aren't. Once you close the editor in use and open it again, things
are back to normal.
</BLOCKQUOTE>
<P><IMG SRC="bar.gif" WIDTH="480" HEIGHT="6" ALIGN="BOTTOM" BORDER="0"><BR>
<BR>
Set the initial values of the properties using the Properties grid. Select the property
you want to change, and then enter the new value at the top of the Properties grid.
After you have entered the new value, click the <U>A</U>pply button to save the setting.
When you exit the form, the necessary HTML is generated and added at the current
cursor position. Figure 15.9 is an example of HTML code generated with the ActiveX
Control Pad. <B><BR>
<BR>
</B><A HREF="Art/15/15fig09.jpg"><B>FIG. 15.9</B></A> <I><BR>
HTML is generated for the added control.</I></P>
<P>This method of inserting an ActiveX control works fine if you don't care where
the control or controls are placed, but if you want the control(s) at specific X
and Y coordinates, you need to use an HTML layout because HTML currently cannot recognize
X, Y, and Z order positioning. HTML layouts allow exact positioning of controls on
a Web page. The ActiveX Control Pad saves the HTML layout in a file with an ALX extension.
When a browser reads the HTML that contains an HTML layout, it loads the HTML layout
from the ALX file. Control Pad provides the HTML Layout Control for creating and
editing these layouts. The HTML Layout Control gives the developer a forms-based
Web page development environment similar to the Visual Basic interface.</P>
<P>To create an HTML layout, select <U>F</U>ile, N<U>e</U>w HTML Layout to open the
HTML Layout Editor. You can click and drag any of the default controls on the Standard
or Additional tabs onto the form. To set the properties, select <U>V</U>iew, <U>P</U>roperties
to display the Properties grid.</P>
<P>To add your ActiveX control, click the right mouse on the bottom of the tab in
the Toolbox where you want the control to reside, and select Additional Controls
to bring up the Additional Controls dialog (see fig. 15.10). <B><BR>
<BR>
</B><A HREF="Art/15/15fig10.jpg"><B>FIG. 15.10</B></A> <I><BR>
The additional Controls dialog lists all registered ActiveX controls.</I></P>
<P>Select the control you want to add by clicking the check box next to its name
in the <U>A</U>vailable Controls list box. Click the OK button to add the control
to the tab, and close the Custom Controls dialog. Now you can use that control as
if it were part of Control Pad.</P>
<P>After you have your controls set up, close the form and save the changes. This
course returns you to the HTML Source Editor. Now that you have created the layout,
you need to add it to the HTML. Click an insertion point anywhere inside the <TT><BODY></TT>
tags, and then select <U>E</U>dit, I<U>n</U>sert HTML Layout. Select the layout you
want to insert, and then click the OK button. The needed HTML will be generated and
placed at the cursor.</P>
<P>The Control Pad is also helpful for creating scripts. Before creating a script,
make sure you set the Script Language for the page. Select <U>T</U>ools, <U>O</U>ptions,
<U>S</U>cript to bring up the Script Options dialog. Select the scripting language
you prefer, and then click the OK key to save your selection.</P>
<P>To create the script, open the Script Wizard by selecting <U>T</U>ools, Script
<U>W</U>izard. Scripts can be created using the <U>L</U>ist View or the Co<U>d</U>e
View. <U>L</U>ist View allows you to insert actions while Co<U>d</U>e View is more
of a code editor. To create a line of code, select an event from the Select an <U>E</U>vent
list box. This selection determines which event the script is being created for.
After the event is selected, select an action, and double-click it to insert it into
the script. If you are in <U>L</U>ist View, you will be prompted to enter any needed
parameters for the selected action. If you are in Co<U>d</U>e View, a skeleton of
the needed command will appear in the Script Pane; you will need to edit the necessary
pieces. You can also add code in the Script Pane.</P>
<P>When you are finished creating the necessary scripts, click the <U>O</U>K key
to add the scripts to the HTML code.</P>
<P>For more information on Control Pad, refer to Control Pad's help files and the
Author/Editing section of Microsoft's Web site.
<H3><A NAME="Heading10"></A>Using the Microsoft Access, Word, and Excel Applications
as ActiveX Control Containers</H3>
<P>When you design a control, you probably think, "It has to work in Microsoft
Visual C++, Microsoft Visual Basic, and on the Internet." What about Office
products? For example, what if someone wants to use a fancy list box control you've
created in a Microsoft Word Document to list the sections of a long document, allowing
the users to pick the section they want to jump to. Microsoft Office 97 makes it
easy to use an ActiveX control in an Office application, even in Microsoft Word.
ActiveX controls can be a very useful addition to Microsoft Office 97, especially
in Microsoft Access, Microsoft Word, and Microsoft Excel.</P>
<P>So how do you add controls to these products? The Microsoft Access menu choices
are a little different than Microsoft Word and Microsoft Excel, but the concepts
are the same. Basically, you choose More Controls from the Controls Toolbox, select
your control from the list, set the properties, and add code to the events.</P>
<P>To add a control to a Microsoft Access form, follow these steps:
<OL>
<LI>To open or create a new form, click the Forms tab of the Database window, which
appears when you first open an existing database or create a new one. To create a
new form, click the <U>N</U>ew button. This action opens the New Form dialog. Select
Design View from the list box, and click the OK button. To select an existing form,
select the form from the list of forms on the forms tab of the Database window, and
then click the <U>D</U>esign button on the Forms tab. This action opens the form
in Design View.
<P>
<LI>If the Toolbox is not visible, select <U>V</U>iew, T<U>o</U>olbox from the Access
menu to display it (see fig. 15.11).
<P><A HREF="Art/15/15fig11.jpg"><B>FIG. 15.11</B></A> <I><BR>
Note the More Controls icon at the bottom of the Toolbox.</I></P>
<LI>Select the More Controls icon from the Toolbox. This displays a list of registered
controls.
<P>
<LI>If your control does not appear, it probably was not registered. To register
it, select <U>T</U>ools, ActiveX <U>C</U>ontrols from the Microsoft Access main menu,
which displays the ActiveX Controls dialog. Click the <U>R</U>egister button, and
select your control's path from the Add ActiveX Control dialog. Then click the Open
button to register it.
<P>
<LI>Select the control you want to add, and then click on the form where you want
the control to appear.
</OL>
<P>To add a control to a Microsoft Word document or a Microsoft Excel spreadsheet,
follow these steps:
<OL>
<LI>Open an existing document or spreadsheet, or use the one opened when you enter.
To create a new document or spreadsheet, click <U>F</U>ile, <U>N</U>ew to open the
New dialog. Click the OK button to use the defaults.
<P>
<LI>If the Control Toolbox is not visible, select <U>V</U>iew, <U>T</U>oolbars, Control
Toolbox from the main menu to display it.
<P>
<LI>Select the More Controls icon from the Control Toolbox. This displays a list
of registered controls (see fig. 15.12).
<P><A HREF="Art/15/15fig12.jpg"><B>FIG. 15.12</B></A> <I><BR>
Select the More Controls icon to display a list of registered controls.</I></P>
<LI>If you need to register your control, select the last item in the list, Register
Custom Control, to display the Register Custom Control dialog. Select your control's
path from the Register Custom Control dialog, and then click the <U>O</U>pen button
to register the control.
<P>
<LI>Select the control you want to add. Microsoft Word places the control at the
cursor position. To place the control on a Microsoft Excel spreadsheet, click on
the spreadsheet where you want the control to appear.
</OL>
<P>Next you need to set the properties for the control. Make sure you are in Design
Mode. Design Mode can be toggled using the View icon on the Form View toolbar in
Microsoft Access (see fig. 15.13) and the Design Mode icon on the Control Toolbox
in Microsoft Word and Microsoft Excel (see fig. 15.14). To set the control's properties,
click with the right mouse on the control, and select <U>P</U>roperties from the
pop-up menu to display the Properties grid. Edit the properties as needed. You can
click with the right mouse on the control and select <I>xxxx </I>Control <U>O</U>bject,
<U>P</U>roperties to use the property pages to edit the properties; <I>xxxx </I>represents
the control name. <B><BR>
<BR>
</B><A HREF="Art/15/15fig13.jpg"><B>FIG. 15.13</B></A> <BR>
<I>Toggle Design Mode in Microsoft Access using the View icon on the Form View Toolbar.</I></P>
<P><A HREF="Art/15/15fig14.jpg"><B>FIG. 15.14</B></A> <BR>
<I>Toggle Design Mode in Microsoft Word and Microsoft Excel using the Design Mode
icon on the Control Toolbox.</I></P>
<P>To create code for events, make sure you are in Design mode. Right-click the control,
and select Build <U>E</U>vent in Microsoft Access, or <U>V</U>iew Code in Microsoft
Word and Microsoft Excel to open the code window. The code window for Microsoft Excel
is shown in Figure 15.15. <B><BR>
<BR>
</B><A HREF="Art/15/15fig15.jpg"><B>FIG. 15.15</B></A> <BR>
<I>The code window for Microsoft Word looks the same as the code window for Microsoft
Excel.</I></P>
<P>You can now code as you would in a Visual Basic code window. To debug your code,
press the F5 key or use the Debug menu.</P>
<P>You can also add an ActiveX control to a report the same way you add it to a form.</P>
<P>For more detailed information, refer to the Microsoft Office 97 Help files and
Microsoft's Knowledge Base found on its Web site (<A HREF="http://www.microsoft.com/kb/"><B>http://www.microsoft.com/kb/</B></A>).</P>
<P>If you compile the project, be sure to recompile if you change the code for your
ActiveX control.
<H2><A NAME="Heading11"></A>Tools for Testing Your Component</H2>
<P>To ensure that your ActiveX control works correctly once in the user's hands,
it needs to be thoroughly tested. Thorough testing involves completely testing every
event, method, and property. The control must also be tested on every platform and,
to the extent possible, with as many of the container applications used by your users
as possible. This part of the chapter discusses using the OLE Control Test Container
packaged with Microsoft Visual C++, your users, and automated testing tools to test
your ActiveX control. You can also use the tools mentioned earlier in the chapter.
<H3><A NAME="Heading12"></A>Visual C++ ActiveX Control Test Container</H3>
<P>The ActiveX Control Test Container can be used to test the properties, methods,
and events functionality of ActiveX controls. You can test the persistence of controls
by saving properties to a stream or substorage, reloading properties, and viewing
the stored stream data. The ActiveX Control Test Container can be integrated with
the Visual C++ debugger, allowing you to step through the control's code.</P>
<P>After you compile and link your control, you can use the Test Container to change
properties, invoke methods, and fire events to test the control. Select <U>T</U>ools,
ActiveX Control Test Container from the Developer Studio menu to load the Test Container.</P>
<P>The first step is to insert your control into the ActiveX Control Test Container.
Select <U>E</U>dit, <U>I</U>nsert OLE Control. This displays the Insert OLE Control
window (see fig. 15.16). Select your control from the <U>O</U>bject Type list box,
and then click the OK button to insert your control. <B><BR>
<BR>
</B><A HREF="Art/15/15fig16.jpg"><B>FIG. 15.16</B></A> <I><BR>
The Insert OLE Control window displays all registered ActiveX controls in the </I><CITE>O</CITE><I>bject
Type list box.</I></P>
<P>If your control is not in the list box, it probably was not registered. Click
the Cancel button to close the Insert OLE Control window, and then use the following
steps to register your control:
<OL>
<LI>Select <U>F</U>ile, Re_gister Controls to open the Controls Registry window.
<P>
<LI>Click the <U>R</U>egister button. Use the Register Controls window to locate
your control.
<P>
<LI>Select your control, and click the <U>O</U>pen button to register the control.
<P>
<LI>Click the <U>C</U>lose button to close the Controls Registry window and return
to the main window.
</OL>
<P>Now that the control is inserted, you can test the property, event, and method
functionality of your control.</P>
<P>You can test changing a property through its property sheets or property dialog.
To change a property via its property sheet, use the following steps:
<OL>
<LI>Click the control you inserted in the main window of Test Container to select
the control.
<P>
<LI>Select <U>E</U>dit, Properties... <I>xxx</I> Control <U>O</U>bject, where <I>xxx</I>
is the name of the control. This step displays the control's property page.
<P>
<LI>Edit the value of the property.
<P>
<LI>Click the <U>A</U>pply button to set the property to the new value.
<P>
<LI>Click the OK button to close the control's property page.
</OL>
<P>To change a property via its property dialog follow these steps:
<OL>
<LI>Click the control you inserted in the main window of Test Container to select
the control.
<LI>Select <U>V</U>iew, <U>P</U>roperties to show the Properties dialog for the control
(see fig. 15.17).
<P><A HREF="Art/15/15fig17.jpg"><B>FIG. 15.17</B></A> <BR>
<I>All of the control's properties may be changed using the Properties dialog.</I></P>
<LI>Select a property from the <U>P</U>roperty combo box. Edit the value in the <U>V</U>alue
text box.
<P>
<LI>Click the <U>A</U>pply button to set the property to the value. If you enter
a value that is the wrong data type, you will hear a beep, and the value will not
be changed.
<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -