【正文】
new project for , choose the New option in the File menu. Under the Projects tab, highlight Win32 Application. In the Location field type an appropriate path name or click the Browse button. Type the word hello in for the project name, and you will see that word echoed in the Location field as well. Click the OK button. In the next window, use the default selection An empty project, click Finish, then click OK once more in the next window. Notice there is an option for the typical Hello World application, however it skips a few important steps you are about to take. Visual C++ will create a new subdirectory named HELLO and place the project files named , , , and in that directory. If you quit and later want to reopen the project, doubleclick on . The area along the left side of the screen will now change so that three tabs are available. The InfoView tab is still there, but there is now also a ClassView and a FileView tab. The ClassView tab will show you a list of all of the classes in your application and the FileView tab gives you a list of all of the files in the project. Now it is time to type in the code for the program. In the File menu select the New option to create a new editor window. In the dialog that appears, make sure the Files tab is 沈陽航空工業(yè)學院北方科技學院畢業(yè)設計 (外文翻譯 ) 10 active and request a C++ Source File. Make sure the Add to Project option is checked for Project hello, and enter hello for File name. Visual C++ es with its own intelligent C++ editor, and you will use it to enter the program s hown above. Type (copy/paste) the code in the listing into the editor window. You will find that the editor automatically colors different pieces of text such as ments, key words, string literals, and so on. If you want to change the colors or turn the coloring off, go to the Options option in the Tools menu, choose the Format tab and select the Source Windows option from the left hand list. If there is some aspect of the editor that displeases you, you may be able to change it using the Editor tab of the Options dialog. After you have finished entering the code, save the file by selecting the Save option in the File menu. Save it to a file named in the new directory Visual C++ created. In the area on the left side of the screen, click the FileView tab and expand the tree on the icon labeled hello files, then expand the tree on the folder icon labeled Source Files. You will see the file named . Click on the ClassView tab and expand the hello classes tree and you will see the classes in the application. You can remove a file from a project at any time by going to the FileView, clicking the file, and pressing the delete button. Finally, you must now tell the project to use the MFC library. If you omit this step the project will not link properly, and the error messages that the linker produces will not help one bit. Choose the Settings option in the Project menu. Make sure that the General tab is selected in the tab at the top of the dialog that appears. In the Microsoft Foundation Classes bo box, choose the third option: Use MFC in a Shared DLL. Then close the dialog. Having created the project file and adjusted the settings, you are ready to pile the program. In the Build menu you will find three different pile options: Compile (only available if the text window for has focus) Build Rebuild All The first option simply piles the source file listed and forms the object file for it. This option does not perform a link, so it is useful only for quickly piling a file to check for errors. The second option piles all of the source files in the project that have been modified since the last build, and then links them to form an executable. The third 沈陽航空工業(yè)學院北方科技學院畢業(yè)設計 (外文翻譯 ) 11 option repiles all of the source files in the project and relinks them. It is a pile and link from scratch option that is useful after you change certain piler options or move to a different platform. In this case, choose the Build option in the Build menu to pile and link the code. Visual C++ will create a new subdirectory named Debug and place the executable named in that new subdirectory. This subdirectory holds all disposable (easily recreated) files generated by the piler, so you can delete this directory when you run short on disk space without fear of losing anything important. If you see piler errors, simply double click on the error message in the output window. The editor will take you to that error. Compare your code against the code above and fix the problem. If you see a mass of linker errors, it probably means that you specified the project type incorrectly in the dialog used to create the project. You may want to simply delete your new directory and recreate it again following the instr uctions given above exactly. To execute the program, choose the Execute option in the Build menu. A window appears with the words hello world. The window itself has the usual decorations: a title bar, resize areas, minimize and maximize buttons, and so on. Inside the window is a static label displaying the words hello world. Note that the program is plete. You can move the window, resize it, minimize it, and cover and uncover it with other windows. With a very small amount of code you have created a plete Window application. This is one of the many advantages of using MFC. All the details are handled elsewhere. 沈陽航空工業(yè)學院北方科技學院畢業(yè)設計 (外文翻譯 ) 12 Visual C++ MFC 簡要介紹 原著: Marshall Brain Visual C++ 不僅僅是一個編譯器。 return TRUE。 }。 }。s controls, the program must respond appropriately. The responses are determined by the user39。s NT, the API is typically referred to as the Win32 API, to distinguish it from the original 16bit API of lowerlevel Windows pro