![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
Creating an MFC ApplicationCreating applications with AppWizard is so easy that we should create one right now just for practice. From Developer Studio, pull down the File menu and select New. The New window, shown in Figure 1.3, will appear. Choose Project Workspace and click on the Create button.
Next, the New Project Workspace window appears (Figure 1.4). This window allows you to use any of the AppWizards that are installed on your computer. Well use the MFC AppWizard to create an MFC-based Multi-Document application. Select MFC AppWizard(exe). Then enter the name of the project. As Figure 1.4 shows, we will use Sample as the name in this example.
Notice that the project name is also used as the directory where the new project will be created. You can modify the path in the Location box to specify another location. After you click on the Create button, the first dialog in the MFC AppWizard will appear. This dialog is shown in Figure 1.5. Here, you can specify if you want to create a Single Document Interface (SDI) application, a Multiple Document Interface (MDI) application, or a dialog-based application. In this example, well use the default selection (MDI).
Pressing Next takes you to the next dialog. Dialogs 2 through 5 let you specify more options for your new application, and we will use the default settings. Figure 1.6 shows the sixth and final MFC AppWizard dialog.
The final dialog allows you to override the names of the classes that will be used in the new project. AppWizard creates suggested class names by appending identifiers such as App, View, and Doc to the project name. For our purposes, the proposed names are acceptable. Press the Finish button to proceed. Before actually creating the application, AppWizard displays a New Project Information window (Figure 1.7) that outlines the settings to be used.
This is your last chance to review your choices. Pressing the OK button creates the application. You can compile the new project by pressing F7, and run the application by pressing F5. Adding an Event HandlerNow that we have a working application, we can modify it with ClassWizard. Using the MFC application that we just created, select ClassWizard from the View menu. Figure 1.8 shows the ClassWizard dialog.
The ClassWizard dialog has five tabs. The Message Maps tab should be selected, as shown in the figure. The dialog shows any installed event handlers for the class shown in the Class name pull-down control. The list box labeled Object IDs contains the class name and a list of menu IDs. You add event handlers by selecting one of the menu IDs or the class name and selecting a message from the list box labeled Messages. Pressing the Add Function button creates the new event handler. Lets create an event handler that will report keystrokes. This can be done by installing an event handler for the WM_KEYDOWN message. Windows posts a WM_KEYDOWN message when any key is pressed. Make sure that the CSampleView class is selected in the Class name box and in the Object IDs list box. Select the WM_KEYDOWN entry in the Messages list box (youll probably have to scroll through the messages to find WM_KEYDOWN). Once you have it selected, press the Add Function button. AppWizard adds WM_KEYDOWN to the Member functions list box and adds the new event handler to your code. Now press the Edit Code button. ClassWizard will display a window with the new code. Figure 1.9 shows the new event handler.
The only thing that the event handler that ClassWizard creates for you does is call the base class version of the same member function. We can add our code where ClassWizard has left a comment to indicate the best place for our code. For this example, well use a TRACE debug macro to display information about the messages that are received. Modify the event handler to look like this: void CSampleView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { TRACE("WM_KEYDOWN message received "); TRACE("keycode=%d repeat=%d flags=%d\n", nChar, nRepCnt, nFlags); CView::OnKeyDown(nChar, nRepCnt, nFlags); } Now, compile and run the application. Once the application window appears, press some keys. The Debug window in Developer Studio will display the TRACE messages.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |