【正文】
ENTER, CRect(50,80,150,150), this)。 啟動(dòng) VC++,如果你是剛剛安裝好,則你會(huì)在屏幕上看到一個(gè)帶有工具欄的空窗口。你所編寫的每個(gè) MFC 程序都有一個(gè)單一的程序?qū)ο?,它是處? MFC 和 Windows 的初始細(xì)節(jié)的。 m_pMainWndUpdateWindow()。 // include // 說明應(yīng)用程序類 class CHelloApp : public CWinApp { public: virtual BOOL InitInstance()。 MFC 為你處理所有的細(xì)節(jié):你建立按鈕并告知它特定的處理函數(shù),則當(dāng)它被按下時(shí),它就會(huì)調(diào)用相應(yīng)的函數(shù)。你的事件循環(huán)中的代碼會(huì)查看結(jié)構(gòu)中不同域,以確定哪個(gè)用戶界面對(duì)象受到了影響,然后會(huì)完成相應(yīng)的操作。在一個(gè)事件驅(qū)動(dòng)界面中,應(yīng)用程序會(huì)在屏幕上繪制幾個(gè)界面對(duì)象,如按鈕、文本區(qū)和菜單。然后程序必須響應(yīng)退出。 從程序員的角度來看,這些系統(tǒng)在概念上是相似的,盡管它們可能有很大的不同。 你所建立的沒一個(gè)應(yīng)用程序都會(huì)使用它自己的一套控制、菜單結(jié)構(gòu)以及對(duì)話框。Windows 的鐘表、 PIF 編輯器、記事本等都是 SDI 應(yīng)用程序的例子。在本教程中,我們將使用代碼來建立它們。這就是事件驅(qū)動(dòng)代碼,它構(gòu)成了所有應(yīng)用程序。它就是 Microsoft 基本類庫 (MFC),該庫的主要優(yōu)點(diǎn)是效率高。傳統(tǒng)上,你需要在紙上做一下用戶界面的草圖,直到對(duì)各元素感到滿意為止。在本節(jié)中,你將會(huì)輸入、編譯和運(yùn)行一個(gè)簡(jiǎn)單的 MFC 程序。 } This small program does three things. First, it creates an application object. Every MFC program you write will have 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 the 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 plete understanding of its structure. The steps necessary to enter and pile 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 tutorials a standard installation is suitable and after answering two or three simple questions the rest of the installation is quick and painless. Start VC++ by double clicking on its icon in the Visual 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 e up in several different 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 dialog that says it was unable to find a certain file, clear the dialog by clicking the No button. Go to the Window menu and select the Close All option if it is available. Go to the File menu and select the Close option if it is available to close any remaining windows. Now you are at the proper starting point. 沈陽航空工業(yè)學(xué)院北方科技學(xué)院畢業(yè)設(shè)計(jì) (外文翻譯 ) 8 If you have just installed the package, you will see a window that looks something like this: 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 right 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 along the side of the window, or close it and later get it back by choosing the Customize option in the Tools menu. What you see now is normal. Along the top is the menu bar and several toolbars. Along the left side are all of the topics available from the online book collection (you might want to explore by double clicking on several of the items you see there the collection of information found in the online books is gigantic). Along the bottom is a status window where various messages will be displayed. Now what? What you would like to do is type in the above program, pile it and run it. Before you start, switch to the File Manager (or the MSDOS prompt) and make sure your drive has at least five megabytes of free space available. Then take the following steps. Creating a Project and Compiling the Code In order to pile 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 project 沈陽航空工業(yè)學(xué)院北方科技學(xué)院畢業(yè)設(shè)計(jì) (外文翻譯 ) 9 concept is quite useful. A project holds three different types of information: It remembers all of the source code files that bine together to create one executable. In this simple example, the file 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 on it simultaneously). The project maintains a list of the different source files and piles all of them as necessary each time you want to create a new executable. It remembers piler and linker options particular to this specific application. For example, it remembers which libraries to link into the executable, whether or not you want to use prepiled headers, and so on. It remembers what type of project you wish to build: a console application, a windows application, etc. If you are familiar with makefiles, then it is easy to think of a project as a machinegenerated makefile that has a very easytounderstand user interface to manipulate it. For now we will create a very simple project file and use it to pile . To create a 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 pr