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

📄 ch25.htm

📁 Learning language of Visual C++6
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>

<HEAD>
<SCRIPT LANGUAGE="JavaScript">

<!--

function popUp(pPage) {
 var fullURL = document.location;
 var textURL = fullURL.toString();
 var URLlen = textURL.length;
 var lenMinusPage = textURL.lastIndexOf("/");
 lenMinusPage += 1;
 var fullPath = textURL.substring(0,lenMinusPage);
 popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394');
 figDoc= popUpWin.document;
 zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>';
 zhtm += '<link rel="stylesheet" href="/includes/stylesheets/ebooks.css"></head>';
 zhtm += '<BODY bgcolor="#FFFFFF">';
 zhtm += '<IMG SRC="' + fullPath + pPage + '">';
 zhtm += '<P><B>' + pPage + '</B>';
 zhtm += '</BODY></HTML>';
 window.popUpWin.document.write(zhtm);
 window.popUpWin.document.close();
 // Johnny Jackson 4/28/98
 }

//-->
                                                                
</SCRIPT>
<link rel="stylesheet" href="/includes/stylesheets/ebooks.css">

	
	<TITLE>Special Edition Using Visual C++ 6 -- Ch 25 -- Achieving Reuse with the Gallery and Your Own AppWizards</TITLE>
</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF">

<CENTER>
<H1><IMG SRC="../button/que.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR>
Special Edition Using Visual C++ 6</H1>
</CENTER>
<CENTER>
<P><A HREF="../ch24/ch24.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch26/ch26.htm"><IMG
SRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"
BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"
HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> 
<HR>

</CENTER>
<CENTER>
<H1>- 25 -</H1>

<H1>Achieving Reuse with the Gallery and Your Own AppWizards</H1>
</CENTER>

<UL>
	<LI><A HREF="#Heading1">Reviewing the Benefits of Writing Reusable Code</A>
	<LI><A HREF="#Heading2">Using Component Gallery</A>
	<UL>
		<LI><A HREF="#Heading3">Adding a Component to the Gallery</A>
		<LI><A HREF="#Heading4">Using Gallery Components in Your Projects</A>
		<LI><A HREF="#Heading5">Exploring the Gallery</A>
	</UL>
	<LI><A HREF="#Heading6">Introducing Custom AppWizards</A>
</UL>

<P>
<HR SIZE="4">

<CENTER>
<H1></H1>
</CENTER>
<P>In these days of complex programs, <I>reusability</I> has become more than a buzzword.
It's become a survival technique for programmers who find themselves with the awesome
task of creating hundreds of thousands of lines of working source code in a minimum
amount of time. Visual C++ is packed with ways to let you reuse the work of programmers
who have gone before you, such as AppWizard, ClassWizard, and of course the Microsoft
Foundation Classes. The tools discussed in this chapter enable you to contribute
code to the future, ready to be reused quickly and easily by some future coworker--or
better yet, by you.</P>
<P>
<H2><A NAME="Heading1"></A>Reviewing the Benefits of Writing Reusable Code</H2>
<P>If you have a job to do, it's easy to see how reusing someone else's code, dialog
boxes, or design simplifies your work and lets you finish faster. As long as you
can trust the provider of the material you reuse, the more you can reuse, the better.
As a result, there's a market for reusable bits and pieces of programs.</P>
<P>In fact, there are two markets: one formal one, with vendors selling project parts
such as controls or templates, and another informal one within many large companies,
with departments developing reusable parts for brownie points or bragging rights,
or other intangibles. Some companies even have a reuse budget to which you can charge
the time you spend making parts of your project reusable, or they award reuse credits
if someone else in the company reuses one of your parts. If yours doesn't, maybe
it should: Reuse can save as much as 60% of your software budget, but only if someone
is noble or charitable enough to develop with reuse in mind or if company policy
inspires everyone to develop with reuse in mind.</P>
<P>Most newcomers to reuse think only of reusing code, but there are other parts
of a project that can save you far more time than you can save with code reuse only.
These include the following:</P>
<P>

<UL>
	<LI><I>Design</I>. The Document/View paradigm, first discussed in Chapter 4, &quot;Documents
	and Views,&quot; is a classic example of a design decision that is reused in project
	after project.
	<P>
	<LI><I>Interface Resources.</I> You can reuse controls, icons, menus, toolbars, or
	entire dialog boxes and reduce training time for your users as well as development
	time for your programmers.
	<P>
	<LI><I>Project Settings.</I> Whether it's an obscure linker setting or the perfect
	arrangement of toolbars, your working environment must be right for you, and getting
	it right is faster on every project you do because you reuse the decisions you made
	the last time.
	<P>
	<LI><I>Documentation.</I> As you read in Chapter 11, &quot;Help,&quot; help text
	for standard commands like File, Open is generated for you by AppWizard. You can
	reuse your own help text from project to project and save even more time.
</UL>

<H2><A NAME="Heading2"></A>Using Component Gallery</H2>
<P>Component Gallery is one way that Developer Studio helps support reuse. Component
Gallery gives you instant access to everything from reusable classes and OLE controls
to wizards. You can even create your own components and add them to Component Gallery.
In fact, in its default installation, Developer Studio automatically adds a category
to Component Gallery for new AppWizard applications that you create.</P>
<P>
<H3><A NAME="Heading3"></A>Adding a Component to the Gallery</H3>
<P>Suppose you have a dialog box that you use frequently in projects. You can create
this dialog box once, add it to Component Gallery, and then merge it into new projects
whenever you need it. To see how this works, follow these steps:</P>
<P>

<DL>
	<DT></DT>
	<DD><B>1. </B>Start a new Custom AppWizard project workspace called App1. (Click
	Finish on Step 1 to use all the default AppWizard settings; then click OK to create
	the project.)
	<P>
	<DT></DT>
	<DD><B>2. </B>Add a new dialog box to the project by choosing Insert, Resource and
	double-clicking Dialog.
	<P>
	<DT></DT>
	<DD><B>3. </B>Using the techniques first presented in Chapter 2, &quot;Dialogs and
	Controls,&quot; build the dialog-box resource shown in Figure 25.1, giving the dialog
	box the resource ID IDD_NAMEDLG.
	<P>
</DL>

<P><A HREF="javascript:popUp('25uvc01.gif')"><B>FIG. 25.1</B></A><B> </B><I>Build
a dialog box to add to Component Gallery.</I></P>

<P><I></I>

<DL>
	<DD><B>4. </B>While the dialog box has focus, bring up ClassWizard and agree to create
	a new class. Call the new class <B>CNameDlg</B>.
	<P>
	<DT></DT>
	<DD><B>5. </B>Close ClassWizard.
	<P>
	<DT></DT>
	<DD><B>6. </B>Right-click CNameDlg in ClassView and choose Add To Gallery from the
	shortcut menu.
	<P>
</DL>

<P>Although nothing appears to happen, the class CNameDlg and the associated resource
have been added to the Gallery. Minimize Developer Studio and browse your hard drive,
starting at My Computer, until you display C:\Program Files\Microsoft VisualStudio\Common\
MSDev98\Gallery (if you installed Visual C++ in another directory, look in that directory
for the MSDev98 folder and continue down from there). As you can see in Figure 25.2,
there is now an App1 folder in the Gallery.</P>
<P><A HREF="javascript:popUp('25uvc02.gif')"><B>FIG. 25.2</B></A><B> </B><I>The Gallery
uses your project name as the folder name when you add a class.</I></P>

<P>Double-click the App1 folder and you'll see it contains one file, Name Dlg.ogx,
as shown in Figure 25.3. The .ogx extension signifies a Gallery component.</P>
<P><A HREF="javascript:popUp('25uvc03.gif')"><B>FIG. 25.3</B></A><B> </B><I>The filename

⌨️ 快捷键说明

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