版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
1、<p> 計算機專業(yè)畢業(yè)設計外文翻譯</p><p> Visual C++ MFC 簡要介紹</p><p> 沈陽航空工業(yè)學院北方科技學院</p><p><b> 2008年7月</b></p><p> 工 學 部 工學一部</p><p> 專 業(yè)計算
2、機科學與技術</p><p> 班 級4418101</p><p> 學 號200413181038</p><p> 姓 名張 為</p><p> 指導教師史 俊</p><p> 負責教師</p><p> Introduction to MFC Programmin
3、g with Visual C++ Version 6.x by Marshall Brain </p><p> Visual C++ is much more than a compiler. It is a complete application development environment
4、that, when used as intended, lets you fully exploit the object oriented nature of C++ to create professional Windows applications. In order to take advantage of these features, you need to understand the C++ programming
5、language. If you have never used C++, please turn to the C++ tutorials in the C/C++ Tutorials page for an introduction. You must then understand the Microsoft Foundation Class (MFC) hier</p><p> These tutor
6、ials introduce the fundamental concepts and vocabulary behind MFC and event driven programming. In this tutorial you will enter, compile, and run a simple MFC program using Visual C++. Tutotial 2 provides a detailed expl
7、anation of the code used in Tutorial 1. Tutorial 3 discusses MFC controls and their customization. Tutorial 4 covers message maps, which let you handle events in MFC.</p><p> What is the Microsoft Foundatio
8、ns Class Library? </p><p> Let's say you want to create a Windows application. You might, for example, need to create a specialized text or drawing editor, or a program that finds files on a large hard
9、disk, or an application that lets a user visualize the interrelationships in a big data set. Where do you begin?</p><p> A good starting place is the design of the user interface. First, decide what the use
10、r should be able to do with the program and then pick a set of user interface objects accordingly. The Windows user interface has a number of standard controls, such as buttons, menus, scroll bars, and lists, that are al
11、ready familiar to Windows users. With this in mind, the programmer must choose a set of controls and decide how they should be arranged on screen. A time-honored procedure is to make a rough sket</p><p> Th
12、e next step is to implement the code. When creating a program for any Windows platform, the programmer has two choices: C or C++. With C, the programmer codes at the level of the Windows Application Program Interface (AP
13、I). This interface consists of a collection of hundreds of C functions described in the Window's API Reference books. For Window's NT, the API is typically referred to as the "Win32 API," to distinguish
14、 it from the original 16-bit API of lower-level Windows products like Window</p><p> Microsoft also provides a C++ library that sits on top of any of the Windows APIs and makes the programmer's job easi
15、er. Called the Microsoft Foundation Class library (MFC), this library's primary advantage is efficiency. It greatly reduces the amount of code that must be written to create a Windows program. It also provides all th
16、e advantages normally found in C++ programming, such as inheritance and encapsulation. MFC is portable, so that, for example, code created under Windows 3.1 can move t</p><p> When you use MFC, you write co
17、de that creates the necessary user interface controls and customizes their appearance. You also write code that responds when the user manipulates these controls. For example, if the user clicks a button, you want to hav
18、e code in place that responds appropriately. It is this sort of event-handling code that will form the bulk of any application. Once the application responds correctly to all of the available controls, it is finished.<
19、;/p><p> You can see from this discussion that the creation of a Windows program is a straightforward process when using MFC. The goal of these tutorials is to fill in the details and to show the techniques yo
20、u can use to create professional applications as quickly as possible. The Visual C++ application development environment is specifically tuned to MFC, so by learning MFC and Visual C++ together you can significantly incr
21、ease your power as an application developer.</p><p> Windows Vocabulary </p><p> The vocabulary used to talk about user interface features and software development in Windows is basic but uniq
22、ue. Here we review a few definitions to make discussion easier for those who are new to the environment.</p><p> Windows applications use several standard user controls:</p><p> Static text la
23、bels </p><p> Push buttons </p><p> List boxes </p><p> Combo boxes (a more advanced form of list) </p><p> Radio boxes </p><p> Check boxes </p>
24、;<p> Editable text areas (single and multi-line) </p><p> Scroll bars </p><p> You can create these controls either in code or through a "resource editor" that can create di
25、alogs and the controls inside of them. In this set of tutorials we will examine how to create them in code. See the tutorials on the AppWizard and ClassWizard for an introduction to the resource editor for dialogs.</p
26、><p> Windows supports several types of application windows. A typical application will live inside a "frame window". A frame window is a fully featured main window that the user can re-size, minimiz
27、e, maximize to fill the screen, and so on. Windows also supports two types of dialog boxes: modal and modeless. A modal dialog box, once on the screen, blocks input to the rest of the application until it is answered. A
28、modeless dialog box can appear at the same time as the application and seems to "float </p><p> Most simple Windows applications use a Single Document Interface, or SDI, frame. The Clock, PIF editor, a
29、nd Notepad are examples of SDI applications. Windows also provides an organizing scheme called the Multiple Document Interface, or MDI for more complicated applications. The MDI system allows the user to view multiple do
30、cuments at the same time within a single instance of an application. For example, a text editor might allow the user to open multiple files simultaneously. When implemented wi</p><p> Each application that
31、you create will use its own unique set of controls, its own menu structure, and its own dialog boxes. A great deal of the effort that goes into creating any good application interface lies in the choice and organization
32、of these interface objects. Visual C++, along with its resource editors, makes the creation and customization of these interface objects extremely easy.</p><p> Event-driven Software and Vocabulary </p&g
33、t;<p> All window-based GUIs contain the same basic elements and all operate in the same way. On screen the user sees a group of windows, each of which contains controls, icons, objects and such that are manipula
34、ted with the mouse or the keyboard. The interface objects seen by the user are the same from system to system: push buttons, scroll bars, icons, dialog boxes, pull down menus, etc. These interface objects all work the sa
35、me way, although some have minor differences in their "look and feel." For </p><p> From a programmer's standpoint, the systems are all similar in concept, although they differ radically in th
36、eir specifics. To create a GUI program, the programmer first puts all of the needed user interface controls into a window. For example, if the programmer is trying to create a simple program such as a Fahrenheit to Celsi
37、us converter, then the programmer selects user interface objects appropriate to the task and displays them on screen. In this example, the programmer might let the user ent</p><p> As the user manipulates t
38、he application's controls, the program must respond appropriately. The responses are determined by the user's actions on the different controls using the mouse and the keyboard. Each user interface object on the
39、screen will respond to events differently. For example, if the user clicks the Quit button, the button must update the screen appropriately, highlighting itself as necessary. Then the program must respond by quitting. No
40、rmally the button manages its appearance it</p><p> Windows follows this same general pattern. In a typical application you will create a main window and place inside it different user interface controls. T
41、hese controls are often referred to as child windows-each control is like a smaller and more specialized sub-window inside the main application window. As the application programmer, you manipulate the controls by sendin
42、g messages via function calls, and they respond to user actions by sending messages back to your code.</p><p> If you have never done any "event-driven" programming, then all of this may seem fore
43、ign to you. However, the event-driven style of programming is easy to understand. The exact details depend on the system and the level at which you are interfacing with it, but the basic concepts are similar. In an event
44、-driven interface, the application paints several (or many) user interface objects such as buttons, text areas, and menus onto the screen. Now the application waits-typically in a piece of code c</p><p> At
45、 the lowest level of abstraction, you have to respond to each event in a fair amount of detail. This is the case when you are writing normal C code directly to the API. In such a scenario, you receive the mouse-click eve
46、nt in some sort of structure. Code in your event loop looks at different fields in the structure, determines which user interface object was affected, perhaps highlights the object in some way to give the user visual fee
47、dback, and then performs the appropriate action for that o</p><p> Fortunately, you can work at a much higher level of abstraction. In MFC, almost all these low-level implementation details are handled for
48、you. If you want to place a user interface object on the screen, you create it with two lines of code. If the user clicks on a button, the button does everything needed to update its appearance on the screen and then cal
49、ls a pre-arranged function in your program. This function contains the code that implements the appropriate action for the button. MFC handle</p><p> An Example </p><p> One of the best ways t
50、o begin understanding the structure and style of a typical MFC program is to enter, compile, and run a small example. The listing below contains a simple "hello world" program. If this is the first time you'
51、;ve seen this sort of program, it probably will not make a lot of sense initially. Don't worry about that. We will examine the code in detail in the next tutorial. For now, the goal is to use the Visual C++ environme
52、nt to create, compile and execute this simple program.</p><p> //hello.cpp</p><p> #include <afxwin.h></p><p> // Declare the application class</p><p> class
53、CHelloApp : public CWinApp</p><p><b> {</b></p><p><b> public:</b></p><p> virtual BOOL InitInstance();</p><p><b> };</b></p&
54、gt;<p> // Create an instance of the application class</p><p> CHelloApp HelloApp;</p><p> // Declare the main window class</p><p> class CHelloWindow : public CFrameWnd&
55、lt;/p><p><b> {</b></p><p> CStatic* cs;</p><p><b> public:</b></p><p> CHelloWindow();</p><p><b> };</b></p>
56、<p> // The InitInstance function is called each</p><p> // time the application first executes.</p><p> BOOL CHelloApp::InitInstance()</p><p><b> {</b></p&g
57、t;<p> m_pMainWnd = new CHelloWindow();</p><p> m_pMainWnd->ShowWindow(m_nCmdShow);</p><p> m_pMainWnd->UpdateWindow();</p><p> return TRUE;</p><p><
58、;b> }</b></p><p> // The constructor for the window class</p><p> CHelloWindow::CHelloWindow()</p><p><b> {</b></p><p> // Create the window i
59、tself</p><p> Create(NULL,</p><p> "Hello World!",</p><p> WS_OVERLAPPEDWINDOW,</p><p> CRect(0,0,200,200));</p><p> // Create a static labe
60、l</p><p> cs = new CStatic();</p><p> cs->Create("hello world",</p><p> WS_CHILD|WS_VISIBLE|SS_CENTER,</p><p> CRect(50,80,150,150),</p><p&g
61、t;<b> this);</b></p><p><b> }</b></p><p> This small program does three things. First, it creates an "application object." Every MFC program you write will h
62、ave a single application object that handles the initialization details of MFC and Windows. Next, the application creates a single window on the screen to act as the main application window. Finally, inside that window t
63、he application creates a single static text label containing the words "hello world". We will look at this program in detail in the next tutorial to gain a complete </p><p> The steps necessary to
64、 enter and compile this program are straightforward. If you have not yet installed Visual C++ on your machine, do so now. You will have the option of creating standard and custom installations. For the purposes of these
65、tutorials a standard installation is suitable and after answering two or three simple questions the rest of the installation is quick and painless.</p><p> Start VC++ by double clicking on its icon in the V
66、isual C++ group of the Program Manager. If you have just installed the product, you will see an empty window with a menu bar. If VC++ has been used before on this machine, it is possible for it to come up in several diff
67、erent states because VC++ remembers and automatically reopens the project and files in use the last time it exited. What we want right now is a state where it has no project or code loaded. If the program starts with a d
68、ialog that</p><p> This screen can be rather intimidating the first time you see it. To eliminate some of the intimidation, click on the lower of the two "x" buttons () that you see in the upper r
69、ight hand corner of the screen if it is available. This action will let you close the "InfoViewer Topic" window. If you want to get rid of the InfoViewer toolbar as well, you can drag it so it docks somewhere a
70、long the side of the window, or close it and later get it back by choosing the Customize option in the Tools menu</p><p> What you see now is "normal". Along the top is the menu bar and several to
71、olbars. Along the left side are all of the topics available from the on-line book collection (you might want to explore by double clicking on several of the items you see there - the collection of information found in th
72、e on-line books is gigantic). Along the bottom is a status window where various messages will be displayed. </p><p> Now what? What you would like to do is type in the above program, compile it and run it.
73、Before you start, switch to the File Manager (or the MS-DOS prompt) and make sure your drive has at least five megabytes of free space available. Then take the following steps.</p><p> Creating a Project an
74、d Compiling the Code </p><p> In order to compile any code in Visual C++, you have to create a project. With a very small program like this the project seems like overkill, but in any real program the proje
75、ct concept is quite useful. A project holds three different types of information:</p><p> It remembers all of the source code files that combine together to create one executable. In this simple example, th
76、e file HELLO.CPP will be the only source file, but in larger applications you often break the code up into several different files to make it easier to understand (and also to make it possible for several people to work
77、on it simultaneously). The project maintains a list of the different source files and compiles all of them as necessary each time you want to create a new executabl</p><p> It remembers compiler and linker
78、options particular to this specific application. For example, it remembers which libraries to link into the executable, whether or not you want to use pre-compiled headers, and so on. </p><p> It remembers
79、what type of project you wish to build: a console application, a windows application, etc. </p><p> If you are familiar with makefiles, then it is easy to think of a project as a machine-generated makefile
80、that has a very easy-to-understand user interface to manipulate it. For now we will create a very simple project file and use it to compile HELLO.CPP.</p><p> To create a new project for HELLO.CPP, choose t
81、he 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
82、, 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
83、 more in the next window. Notice there is an option f</p><p> 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 a
84、lso 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.</p><p> Now it
85、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 active and request a "C++ Source File".
86、Make sure the "Add to Project" option is checked for Project "hello", and enter "hello" for "File name". Visual C++ comes with its own intelligent C++ editor, and you will use it t
87、o enter the program shown above. Type (copy/paste) the code in the listing into the editor window. You </p><p> After you have finished entering the code, save the file by selecting the Save option in the F
88、ile menu. Save it to a file named HELLO.CPP in the new directory Visual C++ created.</p><p> In the area on the left side of the screen, click the FileView tab and expand the tree on the icon labeled "
89、hello files", then expand the tree on the folder icon labeled "Source Files". You will see the file named HELLO.CPP. Click on the ClassView tab and expand the "hello classes" tree and you will se
90、e 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.</p><p> Finally, you must now tell the project
91、 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
92、 General tab is selected in the tab at the top of the dialog that appears. In the Microsoft Foundation Classes combo box, choose the third option: "Use MFC in a Shared DLL." Then close the dialog.</p>&l
93、t;p> Having created the project file and adjusted the settings, you are ready to compile the HELLO.CPP program. In the Build menu you will find three different compile options:</p><p> Compile HELLO.CPP
94、 (only available if the text window for HELLO.CPP has focus) </p><p> Build HELLO.EXE </p><p> Rebuild All </p><p> The first option simply compiles the source file listed and fo
95、rms the object file for it. This option does not perform a link, so it is useful only for quickly compiling a file to check for errors. The second option compiles all of the source files in the project that have been mod
96、ified since the last build, and then links them to form an executable. The third option recompiles all of the source files in the project and relinks them. It is a "compile and link from scratch" option that is
97、 useful </p><p> In this case, choose the Build HELLO.EXE option in the Build menu to compile and link the code. Visual C++ will create a new subdirectory named Debug and place the executable named HELLO.EX
98、E in that new subdirectory. This subdirectory holds all disposable (easily recreated) files generated by the compiler, so you can delete this directory when you run short on disk space without fear of losing anything imp
99、ortant. </p><p> If you see compiler 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 probl
100、em. 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 f
101、ollowing the instructions given above exactly.</p><p> To execute the program, choose the Execute HELLO.EXE option in the Build menu. A window appears with the words "hello world". The window itse
102、lf has the usual decorations: a title bar, re-size 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 complete. You
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 畢業(yè)論文外文翻譯-visualc++mfc簡要介紹
- 基于visualc++的圖像檢測模塊設計-畢業(yè)論文外文翻譯2篇
- 基于VisualC++的花店管理系統(tǒng)的設計與實現(xiàn).pdf
- 畢業(yè)設計外文翻譯---控制系統(tǒng)介紹
- visualc++mfc簡明教程
- 第7章visualc++編程基礎-welcometonginx!
- 齒輪和軸的介紹畢業(yè)設計外文翻譯
- 畢業(yè)設計外文翻譯---齒輪和軸的介紹
- 基于VisualC++的蒸發(fā)式空冷系統(tǒng)優(yōu)化設計軟件開發(fā).pdf
- 計算機專業(yè)畢業(yè)設計-外文翻譯--matlab 介紹
- 畢業(yè)設計外文翻譯
- 機械畢業(yè)設計英文外文翻譯42變速器介紹 (2)
- 機械畢業(yè)設計英文外文翻譯79齒輪和軸的介紹
- 外文翻譯---關于中國象棋的一些簡要介紹
- 基于VisualC++的汽車AMT性能檢測系統(tǒng)軟件平臺設計.pdf
- 網(wǎng)站畢業(yè)設計外文翻譯
- 電氣畢業(yè)設計外文翻譯
- 混凝土畢業(yè)設計外文翻譯
- lyx畢業(yè)設計外文翻譯
- led畢業(yè)設計外文翻譯
評論
0/150
提交評論