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

📄 ch01.htm

📁 VC使用大全。里面集合了VC使用的各种使用技巧。非常有用。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
Sockets. You can produce Internet programs without enabling socket support if you use the new WinInet classes, discussed in <A HREF="index19.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index19.htm" target="text">Chapter 19</A>, &quot;Internet Programming with the WinInet Classes.&quot;</P>

</ul>

<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 main 
frame caption, which appears in the title bar of your application. The file extension, if you choose one, will be incorporated into file names saved by your application and will restrict the files initially displayed when the user chooses <U>F</U>ile, 
<U>O</U>pen.</P>

<A HREF="Bfigs07.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs07.gif"><b>Fig. 1.7</b></A>

<P><I>The Document Template Strings tab of the Advanced Options dialog box lets you adjust the way names are </I><I>abbreviated.</I></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 checkbox, 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&#151;one for each document window, inside the main frame.</P>

<A HREF="Bfigs08.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs08.gif"><b>Fig. 1.8</b></A>

<P><I>The Window Styles tab of the Advanced Options dialog box lets you adjust the appearance of your </I><I>windows.</I></P>

<P>Here are the properties you can set for frames:</P>

<ul>

<li> <I>Thick frame</I>&#151;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>&#151;The frame has a Minimize box in the top-right corner.</P>

<li> <I>Maximize box</I>&#151;The frame has a Maximize box in the top-right corner.</P>

<li> <I>System menu</I>&#151;The frame has a system menu in the top-left corner.</P>

<li> <I>Minimized</I>&#151;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>&#151;The frame is maximized when the application starts. For SDI applications, this option will be ignored when the application is running under Windows 95.</P>

</ul>

<P>When you have made your selections, click Close to return to Step 4 and Next to move on to the next step.</P>

<P><B>Other Options</B></P>

<P>The fifth step in running AppWizard to create an executable Windows program (see Figure 1.9) asks the leftover questions that are not related to menus, OLE, database access, or appearance. Do you want comments inserted in your code? You certainly do. 
That one is easy.</P>

<A HREF="Bfigs09.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs09.gif"><b>Fig. 1.9</b></A>

<P><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 is not so 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 only to find it won't run any more 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 needing to install DLLs as well as the program itself, choose the shared DLL option. The smaller executable is 
convenient for all of you. 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><B>File and Class Names</B></P>

<P>The final step in running AppWizard to create an executable Windows program is to confirm the class names and the file names 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 class names and file names. 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 eight view classes are discussed in <A HREF="index05.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index05.htm" target="text">Chapter 5</A>, &quot;Documents and Views.&quot; Click Finish when this Step 6 dialog box is complete.</P>

<A HREF="Bfigs10.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs10.gif"><b>Fig. 1.10</b></A>

<P><I>The final step of building a typical application with AppWizard is to confirm file names and class names.</I></P>

<P><B>Creating the Application</B></P>

<P>After you click Finish, AppWizard shows you what is going to be created in a dialog box, like that shown in Figure 1.11. If anything here is wrong, click Cancel and then 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 then click OK to actually create the application. This takes a few minutes, which is hardly surprising because hundreds of lines of code, menus, dialog boxes, 
help text, and bitmaps are being generated for you in as many as 20 files. Let it work.</P>

<A HREF="Bfigs11.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs11.gif"><b>Fig. 1.11</b></A>

<P><I>When AppWizard is ready to build your application, you get one more chance to confirm everything.</I></P>

<P><B>Try It Yourself</B></P>

<P>If you haven't started Developer Studio already, do so now. If you've never used it before, you may find the interface a little intimidating. There's a full explanation of all the areas, toolbars, menus, and shortcuts in <A HREF="indexb.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/indexb.htm" 
target="text">Appendix B</A>, &quot;The Developer Studio Interface.&quot;</P>

<P>Bring up AppWizard by choosing <U>F</U>ile, <U>N</U>ew and clicking the Projects tab. On the Projects tab, fill in a folder name where you would like to keep your applications&#151;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 
<U>B</U>uild, <U>B</U>uild from the Developer Studio menu to compile and link the code.</P>

<P>When the build is complete, choose <U>B</U>uild, E<U>x</U>ecute. 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>

<A HREF="Bfigs12.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs12.gif"><b>Fig. 1.12</b></A>

<P><I>Your first application looks like any fully-fledged Windows application.</I></P>

<P>Try out the File menu by choosing <U>F</U>ile, <U>O</U>pen and bring up the familiar Windows File Open dialog (though no matter what file you choose, nothing seems to happen) and then choose <U>F</U>ile, <U>E</U>xit to close the application. Move the 
mouse cursor over one of the toolbar buttons and pause; a tool tip will appear reminding you of the purpose of the toolbar button. Click the Open button to confirm that it is connected to the <U>F</U>ile <U>O</U>pen command you chose earlier. Bring up the 
<U>V</U>iew menu and click <U>T</U>oolbar to hide the toolbar, then choose <U>V</U>iew <U>T</U>oolbar 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>

<A HREF="Bfigs13.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs13.gif"><b>Fig. 1.13</b></A>

<P><I>You even get an About box in this start application.</I></P>

<P>Repeat these steps to create an MDI application called <B>FirstMDI</B>. The creation process will only differ 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 like Figure 1.14, an MDI application with a single document open. Try out the same operations you tried with FirstSDI.</P>

<A HREF="Bfigs14.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs14.gif"><b>Fig. 1.14</b></A>

<P><I>An MDI application can display a number of documents at once.</I></P>

<P>Choose <U>F</U>ile, <U>N</U>ew, and a second window, FirstM2, appears. Try minimizing, maximizing, and restoring these windows. Switch among them using the <U>W</U>indow menu. All this functionality is yours from AppWizard and you don't have to write a 
single line of code to get it.</P>

<H3><B>Creating A Dialog-Based Application</B></H3>

<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 they cannot have a document, and so cannot support database access or compound documents. To create a dialog-based application, start AppWizard as you did for the SDI or MDI application, but on Step 1 choose a dialog-based application, as 
shown in Figure 1.15.</P>

<A HREF="Bfigs15.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs15.gif"><b>Fig. 1.15</b></A>

<P><I>To create a dialog-based application, specify your preference in Step 1 of the AppWizard process.</I></P>

<P>Choose <font color="#008000">Dialog Based</font> and click <font color="#008000">Next</font> to move to Step 2, shown in Figure 1.16.</P>

<A HREF="Bfigs16.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs16.gif"><b>Fig. 1.16</b></A>

<P><I>Step 2 of the AppWizard process for a dialog-based application involves choosing Help, Automation, </I><I>ActiveX, and Sockets settings.</I></P>

<P>If you would like an <U>A</U>bout item on the system menu, select the About Box item. To have AppWizard lay the framework for Help, select the Context Sensitive Help<font color="#008000"> </font>option. The third checkbox, 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 <A HREF="index16.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/index16.htm" target="text">Chapter 16</A>, &quot;Building an Automation 
Server,&quot; select the Automation checkbox. If you want your application to contain ActiveX controls, select the ActiveX<font color="#008000"> </font>Controls checkbox. 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 they have no document.) Click <font color="#008000">Next</font> to move to the third step, shown in Figure 1.17.</P>

<A HREF="Bfigs17.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs17.gif"><b>Fig. 1.17</b></A>

<P><I>Step 3 of the AppWizard process for a dialog-based application deals with comments and the MFC library.</I></P>

<P>As with the SDI and MDI applications created earlier, you want comments in your code. The decision between static linking and a shared DLL is also the same as for the SDI and MDI applications. If your users are likely to have the MFC DLLs already 
(because they are developers or because they have another product that uses the DLL), or if they won't mind installing the DLLs as well as your executable, go with the shared DLL to make a smaller executable file and a faster link. Otherwise choose As A 
Statically Linked Library. Click <font color="#008000">Next</font> to move to the final step, shown in Figure 1.18.</P>

<A HREF="Bfigs18.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs18.gif"><b>Fig. 1.18</b></A>

<P><I>Step 4 of the AppWizard process for a dialog-based application gives you a chance to adjust file and class </I><I>names.</I></P>

<P>In this step you can change the names AppWizard chooses for files and classes. This is rarely a good idea, because it will confuse people who maintain your code if the file names can't be easily determined from the class names, and vice versa. If you 
realize after looking at this dialog that you made a poor choice of project name, use <font color="#008000">Back</font> to move all the way back to the New Project Workspace dialog, change the name, click <font color="#008000">Create</font>, and then use 
<font color="#008000">Next</font> to return to this dialog. Click <font color="#008000">Finish</font> to see the summary of the files and classes to be created, like that in Figure 1.19.</P>

<A HREF="Bfigs19.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs19.gif"><b>Fig. 1.19</b></A>

<P><I>AppWizard confirms the files and classes before creating them.</I></P>

<P>If any of the information on this dialog is not what you wanted, click <font color="#008000">Cancel</font> and then use <font color="#008000">Back</font> to move to the appropriate step and change your choices. When the information is right, click 
<font color="#008000">OK</font> and watch as the application is created.</P>

<P><B>Try It Yourself</B></P>

<P>Create an empty dialog-based application yourself, call it FirstDialog, and accept the defaults for each step of AppWizard. When it's complete, choose <U>B</U>uild <U>B</U>uild to compile and link the application. Choose Build <U>E</U>xecute to see it 
in action. Figure 1.20 shows the empty dialog-based application running.</P>

<A HREF="Bfigs20.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs20.gif"><b>Fig. 1.20</b></A>

<P><I>A starter dialog application includes a reminder of the work you have ahead of you.</I></P>

<P>Clicking the OK or Cancel buttons, or the X in the top right corner, makes the dialog disappear. Clicking the system menu in the top left corner gives you a choice of Move, Close, or About. Figure 1.21 shows the About box that was generated for 
you.</P>

<A HREF="Bfigs21.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch01/Bfigs21.gif"><b>Fig. 1.21</b></A>

<P><I>The same About box is generated for SDI, MDI, and dialog-based applications.</I></P>

<H3><B>Creating DLLs, Console Applications, and More</B></H3>

<P>Although most people use AppWizard to create an executable program, it can make many other kinds of projects. You choose <U>F</U>ile, <U>N</U>ew and then the Projects tab as discussed at the start of this chapter, but choose a different wizard from the 
list on the left of the New dialog box, shown in Figure 1.1. The following are some of the other projects AppWizard can create:</P>

<ul>

<li> ATL COM AppWizard</P>

<li> Custom AppWizard</P>

<li> Database Project</P>

<li> DevStudio Add-in Wizard</P>

<li> ISAPI Extension Wizard</P>

<li> Makefile</P>

<li> MFC ActiveX ControlWizard</P>

<li> MFC AppWizard (dll)</P>

<li> New Database Wizard</P>

<li> Win32 Application</P>

⌨️ 快捷键说明

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