📄 ch01.htm
字号:
applications and also to serve its objects to other applications, choose Both Container
and Server.
</UL>
<P>If you choose to support compound documents, you can also support <I>compound
files</I>. Compound files contain one or more ActiveX objects and are saved in a
special way so that one of the objects can be changed without rewriting the whole
file. This spares you a great deal of time. Use the radio buttons in the middle of
this Step 3 dialog box to say Yes, Please, or No, Thank You to compound files.</P>
<P>If you want your application to surrender control to other applications through
automation, check the Automation check box. (Automation is the subject of Chapter
16, "Building an Automation Server.") If you want your application to use
ActiveX controls, select the ActiveX Controls check box. Click Next to move to the
next step.</P>
<BLOCKQUOTE>
<P>
<HR>
<strong>NOTE:</strong> If you want your application to <I>be</I> an ActiveX control, you
don't create a typical .exe application as described in this section. Creating ActiveX
controls with the ActiveX ControlWizard is covered in Chapter 17, "Building
an ActiveX Control." 
<HR>
</BLOCKQUOTE>
<H3><A NAME="Heading5"></A>Appearance and Other Options</H3>
<P>The fourth step in running AppWizard to create an executable Windows program (see
Figure 1.6) is to determine some of the interface appearance options for your application.
This Step 4 dialog box contains a number of independent check boxes. Check them if
you want a feature; leave them unchecked if you don't.</P>
<P><A HREF="javascript:popUp('01uvc06.gif')"><B>FIG. 1.6</B></A><B> </B><I>The fourth
step of building a typical application with AppWizard is to set some interface options.</I></P>
<P>The following are the options that affect your interface's appearance:</P>
<UL>
<LI><I>Docking Toolbar</I>. AppWizard sets up a toolbar for you. You can edit it
to remove unwanted buttons or to add new ones linked to your own menu items. This
is described in Chapter 9, "Status Bars and Toolbars."
<P>
<LI><I>Initial Status Bar</I>. AppWizard creates a status bar to display menu prompts
and other messages. Later, you can write code to add indicators and other elements
to this bar, as described in Chapter 9.
<P>
<LI><I>Printing and Print Preview</I>. Your application will have Print and Print
Preview options on the File menu, and much of the code you need in order to implement
printing will be generated by AppWizard. Chapter 6, "Printing and Print Preview,"
discusses the rest.
<P>
<LI><I>Context-Sensitive Help</I>. Your Help menu will gain Index and Using Help
options, and some of the code needed to implement Help will be provided by AppWizard.
This decision is hard to change later because quite a lot of code is added in different
places when implementing Context-Sensitive Help. Chapter 11, "Help," describes
Help implementation.
<P>
<LI><I>3D Controls</I>. Your application will look like a typical Windows 95 application.
If you don't select this option, your dialog boxes will have a white background,
and there will be no shadows around the edges of edit boxes, check boxes, and other
controls.
<P>
<LI><I>MAPI(Messaging API)</I>. Your application will be able to use the Messaging
API to send fax, email, or other messages. Chapter 18, "Sockets, MAPI, and the
Internet," discusses the Messaging API.
<P>
<LI><I>Windows</I> <I>Sockets</I>. Your application can access the Internet directly,
using protocols like FTP and HTTP (the World Wide Web protocol). Chapter 18 discusses
sockets. You can produce Internet programs without enabling socket support if you
use the new WinInet classes, discussed in Chapter 19, "Internet Programming
with the WinInet Classes."
</UL>
<P>You can ask AppWizard to build applications with "traditional" toolbars,
like those in Word or Visual C++ itself, or with toolbars like those in Internet
Explorer. You can read more about this in Chapter 9.</P>
<P>You can also set how many files you want to appear on the recent file list for
this application. Four is the standard number; change it only if you have good reason
to do so.</P>
<P>Clicking the Advanced button at the bottom of this Step 4 dialog box brings up
the Advanced Options dialog box, which has two tabs. The Document Template Strings
tab is shown in Figure 1.7. AppWizard builds many names and prompts from the name
of your application, and sometimes it needs to abbreviate your application name.
Until you are familiar with the names AppWizard builds, you should check them on
this Document Template Strings dialog box and adjust them, if necessary. You can
also change the mainframe caption, which appears in the title bar of your application.
The file extension, if you choose one, will be incorporated into filenames saved
by your application and will restrict the files initially displayed when the user
chooses File, Open.</P>
<P>The Window Styles tab is shown in Figure 1.8. Here you can change the appearance
of your application quite dramatically. The first check box, Use Split Window, adds
all the code needed to implement splitter windows like those in the code editor of
Developer Studio. The remainder of the Window Styles dialog box sets the appearance
of your <I>main frame</I> and, for an MDI application, of your <I>MDI child frames</I>.
Frames hold windows; the system menu, title bar, minimize and maximize boxes, and
window edges are all frame properties. The main frame holds your entire application.
An MDI application has a number of MDI child frames--one for each document window,
inside the main frame.</P>
<P><A HREF="javascript:popUp('01uvc07.gif')"><B>FIG. 1.7</B></A><B> </B><I>The Document
Template Strings tab of the Advanced Options dialog box lets you adjust the way names
are abbreviated.</I></P>
<P><A HREF="javascript:popUp('01uvc08.gif')"><B>FIG. 1.8</B></A><B> </B><I>The Window
Styles tab of the Advanced Options dialog box lets you adjust the appearance of your
windows.</I></P>
<P>Here are the properties you can set for frames:</P>
<UL>
<LI><I>Thick Frame</I>. The frame has a visibly thick edge and can be resized in
the usual Windows way. Uncheck this to prevent resizing.
<P>
<LI><I>Minimize Box</I>. The frame has a minimize box in the top-right corner.
<P>
<LI><I>Maximize Box</I>. The frame has a maximize box in the top-right corner.
<P>
<LI><I>System Menu</I>. The frame has a system menu in the top-left corner.
<P>
<LI><I>Minimized. </I>The frame is minimized when the application starts. For SDI
applications, this option will be ignored when the application is running under Windows
95.
<P>
<LI><I>Maximized</I>. The frame is maximized when the application starts. For SDI
applications, this option will be ignored when the application is running under Windows
95.
</UL>
<P>When you have made your selections, click Close to return to step 4 and click
Next to move on to the next step.</P>
<P>
<H3><A NAME="Heading6"></A>Other Options</H3>
<P>The fifth step in running AppWizard to create an executable Windows program (see
Figure 1.9) asks the leftover questions that are unrelated to menus, OLE, database
access, or appearance. Do you want comments inserted in your code? You certainly
do. That one is easy.</P>
<P><A HREF="javascript:popUp('01uvc09.gif')"><B>FIG. 1.9</B></A><B> </B><I>The fifth
step of building an application with AppWizard is to decide on comments and the MFC
library.</I></P>
<P>The next question isn't as straightforward. Do you want the MFC library as a shared
DLL or statically linked? A <I>DLL</I> (dynamic link library) is a collection of
functions used by many different applications. Using a DLL makes your programs smaller
but makes the installation a little more complex. Have you ever moved an executable
to another directory, or another computer, only to find it won't run anymore because
it's missing DLLs? If you statically link the MFC library into your application,
it is larger, but it is easier to move and copy around.</P>
<P>If your users are likely to be developers themselves and own at least one other
application that uses the MFC DLL or aren't intimidated by the need to install DLLs
as well as the program itself, choose the shared DLL option. The smaller executable
is convenient for all. If your users are not developers, choose the statically linked
option. It reduces the technical support issues you have to face with inexperienced
users. If you write a good install program, you can feel more confident about using
shared DLLs.</P>
<P>After you've made your Step 5 choices, click Next to move to Step 6.</P>
<P>
<H3><A NAME="Heading7"></A>Filenames and Classnames</H3>
<P>The final step in running AppWizard to create an executable Windows program is
to confirm the classnames and the filenames that AppWizard creates for you, as shown
in Figure 1.10. AppWizard uses the name of the project (FirstSDI in this example)
to build the classnames and filenames. You should not need to change these names.
If your application includes a view class, you can change the class from which it
inherits; the default is CView, but many developers prefer to use another view, such
as CScrollView or CEditView. The view classes are discussed in Chapter 4. Click Finish
when this Step 6 dialog box is complete.</P>
<BLOCKQUOTE>
<P>
<HR>
<strong>TIP:</strong> Objects, classes, and inheritance are reviewed in Appendix A, "C++
Review and Object-Oriented Concepts."
<HR>
</BLOCKQUOTE>
<P><A HREF="javascript:popUp('01uvc10.gif')"><B>FIG. 1.10</B></A><B> </B><I>The final
step of building a typical application with AppWizard is to confirm filenames and
classnames.</I><B></B></P>
<H3><A NAME="Heading8"></A>Creating the Application</H3>
<P>After you click Finish, AppWizard shows you what is going to be created in a dialog
box, similar to Figure 1.11. If anything here is wrong, click Cancel and work your
way back through AppWizard with the Back buttons until you reach the dialog box you
need to change. Move forward with Next, Finish; review this dialog box again; and
click OK to actually create the application. This takes a few minutes, which is hardly
surprising because hundreds of code lines, menus, dialog boxes, help text, and bitmaps
are being generated for you in as many as 20 files. Let it work.</P>
<P><A HREF="javascript:popUp('01uvc11.gif')"><B>FIG. 1.11</B></A><B> </B><I>When
AppWizard is ready to build your application, you get one more chance to confirm
everything.</I></P>
<P>
<H3><A NAME="Heading9"></A>Try It Yourself</H3>
<P>If you haven't started Developer Studio already, do so now. If you've never used
it before, you may find the interface intimidating. There's a full explanation of
all the areas, toolbars, menus, and shortcuts in Appendix C, "The Visual Studio
User Interface, Menus, and Toolbars."</P>
<P>Bring up AppWizard by choosing File, New and clicking the Projects tab. On the
Projects tab, fill in a folder name where you would like to keep your applications;
AppWizard will make a new folder for each project. Fill in <B>FirstSDI</B> for the
project name; then move through the six AppWizard steps. Choose an SDI application
at Step 1, and on all the other steps simply leave the selections as they are and
click Next. When AppWizard has created the project, choose Build, Build from the
Developer Studio menu to compile and link the code.</P>
<P>When the build is complete, choose Build, Execute. You have a real, working Windows
application, shown in Figure 1.12. Play around with it a little: Resize it, minimize
it, maximize it.</P>
<P><A HREF="javascript:popUp('01uvc12.gif')"><B>FIG. 1.12</B></A><B> </B><I>Your
first application looks like any full-fledged Windows application.</I></P>
<P>Try out the File menu by choosing File, Open; bring up the familiar Windows File
Open dialog (though no matter what file you choose, nothing seems to happen); and
then choose File, Exit to close the application. Execute the program again to continue
exploring the capabilities that have been automatically generated for you. Move the
mouse cursor over one of the toolbar buttons and pause; a ToolTip will appear, reminding
you of the toolbar button's purpose. Click the Open button to confirm that it is
connected to the File Open command you chose earlier. Open the View menu and click
Toolbar to hide the toolbar; then choose View Toolbar again to restore it. Do the
same thing with the status bar. Choose Help, About, and you'll see it even has an
About box with its own name and the current year in the copyright date (see Figure
1.13).</P>
<P>Repeat these steps to create an MDI application called <I>FirstMDI</I>. The creation
process will differ only on Step 0, where you specify the project name, and Step
1, where you choose an MDI application. Accept the defaults on all the other steps,
create the application, build it, and execute it. You'll see something similar to
Figure 1.14, an MDI application with a single document open. Try out the same operations
you tried with FirstSDI.</P>
<P><A HREF="javascript:popUp('01uvc13.gif')"><B>FIG. 1.13</B></A><B> </B><I>You even
get an About box in this start application.</I></P>
<P><A HREF="javascript:popUp('01uvc14.gif')"><B>FIG. 1.14</B></A><B> </B><I>An MDI
application can display a number of documents at once.</I></P>
<P>Choose File, New, and a second window, FirstM2, appears. Try minimizing, maximizing,
and restoring these windows. Switch among them using the Window menu. All this functionality
is yours from AppWizard, and you don't have to write a single line of code to get
it.</P>
<P>
<H2><A NAME="Heading10"></A>Creating a Dialog-Based Application</H2>
<P>A dialog-based application has no menus other than the system menu, and it cannot
save or open a file. This makes it good for simple utilities like the Windows Character
Map. The AppWizard process is a little different for a dialog-based application,
primarily because such applications can't have a document and therefore can't support
database access or compound documents. To create a dialog-based application, start
AppWizard as you did for the SDI or MDI application, but in Step 1 choose a dialog-based
application, as shown in Figure 1.15. Call this application <B>FirstDialog</B>.</P>
<P><A HREF="javascript:popUp('01uvc15.gif')"><B>FIG. 1.15</B></A><B> </B><I>To create
a dialog-based application, specify your preference in Step 1 of the AppWizard process.</I></P>
<P>Choose Dialog Based and click Next to move to Step 2, shown in Figure 1.16.</P>
<P><A HREF="javascript:popUp('01uvc16.gif')"><B>FIG. 1.16</B></A><B> </B><I>Step
2 of the AppWizard process for a dialog-based application involves choosing Help,
Automation, ActiveX, and Sockets settings.</I></P>
<P>If you would like an About item on the system menu, select the About Box item.
To have AppWizard lay the framework for Help, select the Context-Sensitive Help option.
The third check box, 3D Controls, should be selected for most Windows 95 and Windows
NT applications. If you want your application to surrender control to other applications
through automation, as discussed in Chapter 16, select the Automation check box.
If you want your application to contain ActiveX controls, select the ActiveX Controls
check box. If you are planning to have this application work over the Internet with
sockets, check the Windows Sockets box. (Dialog-based apps can't use MAPI because
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -