📄 ch25.htm
字号:
for your Gallery component is based on the classname.</I></P>
<P><I></I>
<H3><A NAME="Heading4"></A>Using Gallery Components in Your Projects</H3>
<P>Now that you've added the resource and associated class to the Gallery, a logical
next step is to make another project that will use them. Create a MFC AppWizard (exe)
application, called App2, with AppWizard. Again, click Finish on Step 1 to accept
all the defaults and then OK to create the project.</P>
<P>Click the ClassView tab and expand the App2 classes. There are six: CAboutDlg,
CApp2App, CApp2Doc, CApp2View, CChildFrame, and CMainFrame.</P>
<P>Choose Project, Add To Project, and Components and Controls. The Gallery dialog
box, shown in Figure 25.4, appears.</P>
<P><A HREF="javascript:popUp('25uvc04.gif')"><B>FIG. 25.4</B></A><B> </B><I>Gallery
components are arranged in folders.</I></P>
<P>Double-click App1 and you'll see Name Dlg.ogx again. Double-click it. When prompted,
confirm that you want to insert this component in your project. Click Close to close
the Gallery.</P>
<P>Look at ClassView again. CNameDlg has been added. Check FileView and you'll see
that NameDlg.cpp and NameDlg.h have been added to the project. Switch to ResourceView
to confirm that the dialog box IDD_NAMEDLG has been added. You can use this resource
in App2 in just the way you used it in App1.</P>
<P>
<H3><A NAME="Heading5"></A>Exploring the Gallery</H3>
<P>You can use Component Gallery to manage many other component types, including
those that you might get from a friend or buy from a third-party supplier. Component
Gallery can add, delete, import, and edit components in a variety of ways, depending
on the type of component with which you're working. Take some time to experiment
with Component Gallery, and you'll soon see how easy it is to use.</P>
<P>Figure 25.5 shows the contents of the Registered ActiveX Controls folder, reached
by choosing Project, Add to Project, Components and Controls. Both the ATL and MFC
versions of the Dieroll control are here: DieRoll Class was built in Chapter 21,
"The Active Template Library," and Dieroll Control was built in Chapter
17, "Building an ActiveX Control." Before this shot was taken, DBGrid Control
was highlighted and the More Info button was clicked. Components can be bundled with
a Help file that is reached from the More Info button.</P>
<P>
<H2><A NAME="Heading6"></A>Introducing Custom AppWizards</H2>
<P>AppWizard is a sensational tool for starting projects effortlessly. However, because
of its general nature, AppWizard makes many assumptions about the way you want a
new project created. Sometimes you may need a special type of AppWizard project that
isn't supported by the default AppWizard. If this special project is a one-time deal,
you'll probably just create the project by hand. However, if you need to use this
custom project type again and again, you might want to consider creating a custom
AppWizard.</P>
<P><A HREF="javascript:popUp('25uvc05.gif')"><B>FIG. 25.5</B></A><B> </B><I>All ActiveX
controls are available through the Gallery.</I></P>
<P>You can create a custom AppWizard in three ways: using the existing AppWizard
steps as a starting point, using an existing project as a starting point, or starting
completely from scratch. However, no matter what method you choose, creating a custom
AppWizard can be a complicated task, requiring that you understand and be able to
write script files by using the macros and commands that Visual C++ provides for
this purpose.</P>
<P>The following tackles the very simplest case first, creating an AppWizard to reproduce
an existing project with a different name. Follow these steps:</P>
<P>
<DL>
<DT></DT>
<DD><B>1. </B>Create a project in the usual way. Call it <B>Original</B> and click
Finish on Step 1 to accept all the AppWizard defaults.
<P>
<DT></DT>
<DD><B>2. </B>Edit the About box to resemble Figure 25.6.
<P>
</DL>
<P><A HREF="javascript:popUp('25uvc06.gif')"><B>FIG. 25.6</B></A><B> </B><I>Customize
your About box.</I></P>
<P><I></I>
<DL>
<DD><B>3. </B>Choose File, New and click the Projects tab. Select Custom AppWizard
and enter <B>OrigWiz</B>, as shown in Figure 25.7. Click OK.
<P>
<DT></DT>
<DD><B>4. </B>The first of two custom AppWizard dialog boxes appears, as shown in
Figure 25.8. Select An Existing Project to base your wizard on the project you created
in steps 1 and 2. Do not edit the wizard's name. Click Next.
<P>
</DL>
<P><A HREF="javascript:popUp('24uvc07.gif')"><B>FIG. 25.7</B></A><B> </B><I>Create
a custom AppWizard.</I></P>
<P><A HREF="javascript:popUp('24uvc08.gif')"><B>FIG. 25.8</B></A><B> </B><I>Base
your wizard on an existing project.</I></P>
<P><I></I>
<DL>
<DD><B>5. </B>The second custom AppWizard dialog box appears. Browse to the project
file for the Original project, Original.dsp. Click Finish.
<P>
<DT></DT>
<DD><B>6. </B>The New Project Information dialog box, shown in Figure 25.9, confirms
your choices. Click OK.
<P>
</DL>
<P>You are now working on the OrigWiz project, and in many cases you would add code
at this point. Because this is an example, just build the project immediately.</P>
<P>To use your custom AppWizard, choose File, New again and click the Projects tab.
As shown in Figure 25.10, OrigWizard has been added to the list of choices on the
left. Select it and enter <B>App3</B> for the name of the project. Click OK.</P>
<BLOCKQUOTE>
<P>
<HR>
<strong>NOTE:</strong> When you compile the custom AppWizard, Developer Studio creates the
final files and stores them in your C:\Program Files\Microsoft Visual Studio\Common\MSDev98\
Template directory. The next time you choose to start a new project workspace, your
custom AppWizard will be listed in the project types. To remove the custom AppWizard,
delete the wizard's .awx and .pdb files from your C:\Program Files\Microsoft Visual
Studio\Common\MSDev98\Template directory. 
<HR>
</BLOCKQUOTE>
<P><A HREF="javascript:popUp('24uvc09.gif')"><B>FIG. 25.9</B></A><B> </B><I>Your
custom AppWizard creates copies of the Original project with different names.</I></P>
<P><A HREF="javascript:popUp('24uvc10.gif')"><B>FIG. 25.10</B></A><B> </B><I>Your
custom AppWizard has been added to the list of AppWizards.</I></P>
<P>Figure 25.11 shows one of the tasks that you normally complete before you build
the AppWizard: generating the text for the New Project Information dialog box. Click
OK.</P>
<P>Look at the classnames and the code--App3 looks like any of the projects created
in this chapter that accept all the AppWizard defaults, but you didn't have to go
through any dialog steps. Switch to ResourceView and edit IDD_ABOUTBOX. As Figure
25.12 shows, it contains the extra text (based on Original 1.0) that you added, but
the application name on the top line of the box has been correctly changed to App3.
This is one smart wizard.</P>
<P>When you build a wizard from an existing project, all the classes, resources,
and code that you added will be incorporated in the new projects you generate with
the wizard. It's a great time-saver.</P>
<P><A HREF="javascript:popUp('24uvc11.gif')"><B>FIG. 25.11</B></A><B> </B><I>You
have to write the text for the New Project Information dialog box.</I></P>
<P><A HREF="javascript:popUp('24uvc12.gif')"><B>FIG. 25.12</B></A><B> </B><I>AppWizard
copied your custom About box to the new project.</I></P>
<P>You can also build custom AppWizards that present dialog boxes for you to fill
out. Before you do that, you should be comfortable writing wizards that are not AppWizards,
like the ones discussed in Chapter 12, "Property Pages and Sheets." You
should also have generated lots of different types of applications so that you have
a feel for the sort of work AppWizard does. When you're ready, check the section
in the online help titled "Creating Custom AppWizards."</P>
<P>This whole book demonstrates the value of using other people's designs, classes,
code, controls, dialog boxes, and other project parts. This chapter shows two simple
ways to arrange for other people (or you, in the future) to reuse your code, which
benefits your customers or employer by saving significant development time. Your
job will be more enjoyable when repetitive tasks, such as building a dialog box and
associating it with a class, are taken care of, freeing you to do the fun stuff.</P>
<H1></H1>
<CENTER>
<P>
<HR>
<A HREF="ch24.htm" tppabs="http://www.fintech.ru/library/prog/SEUsingVC6/ch24/ch24.htm"><IMG SRC="previous.gif" tppabs="http://www.fintech.ru/library/prog/SEUsingVC6/button/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="ch26.htm" tppabs="http://www.fintech.ru/library/prog/SEUsingVC6/ch26/ch26.htm"><IMG
SRC="next.gif" tppabs="http://www.fintech.ru/library/prog/SEUsingVC6/button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"
BORDER="0"></A><A HREF="index.htm" tppabs="http://www.fintech.ru/library/prog/SEUsingVC6/index.htm"><IMG SRC="contents.gif" tppabs="http://www.fintech.ru/library/prog/SEUsingVC6/button/contents.gif" WIDTH="128"
HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <BR>
<BR>
</P>
<P>© <A HREF="copy.htm" tppabs="http://www.fintech.ru/library/prog/SEUsingVC6/copy.htm">Copyright</A>, Macmillan Computer Publishing. All
rights reserved.
</CENTER>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -