The Steps in Writing Phone Book with the Microsoft Foundation Classes

You'll write the Phone Book program with the Microsoft Foundation Classes in 14 steps, spread over three chapters of the tutorial. The 14 steps can be summarized as follows:

1.Create a simplified data interface (Chapter 4).

Phone Book uses two CPersonList objects, one for the database and one for any person objects found with its search facilities. The simplest way to manage these lists and the mechanisms needed to use them is to encapsulate the lists and mechanisms in another object. Class CDataBase lets the program access data through a single clean interface, regardless of which of the two lists is current. Add class CDataBase. For more information about this step, see “Create a Simplified Data Interface” on page 122.

2.Copy and modify the Hello files (Chapter 5).

To use Hello as a template, you need to copy HELLO.H to VIEW.H and HELLO.CPP to VIEW.CPP. Then you need to modify some of the items in the new copies and add other items. For more information about this step, see “Work from a Template” on page 152.

3.Add two kinds of dialog boxes (Chapter 5).

Phone Book needs two dialog boxes: one for entering a string, used as the name to search for, and one for entering or editing the data for a person. Add classes for these dialog boxes. For more information about this step, see “Add Dialog Boxes” on page 153 in Chapter 5.

4.Determine what messages will be handled (Chapter 6).

Design the application's menus and list the Windows messages your code needs to handle. When the user chooses a command from the menu, a WM_COMMAND message is sent to the appropriate window along with information identifying which menu command is being generated. The application also needs to handle other Windows messages, such as WM_PAINT.

Phone Book has more than a dozen menu commands and responds to almost as many other Windows messages. For more information about this step, see “Determine What Messages Will Be Handled” on page 197 in Chapter 6.

5.Add message-handler functions for File menu commands (Chapter 6).

Phone Book has several File menu commands. Each command needs a handler defined as a member function of class CMainWindow and a corresponding entry in the message map of CMainWindow. Add these functions. For more information about this step, see “Add Message Handlers for File Menu Commands” on page 205 in Chapter 6.

6.Add message-handler functions for Person menu commands (Chapter 6).

Phone Book has several Person menu commands. Each command needs a handler defined as a member function of class CMainWindow and a corresponding entry in the message map of CMainWindow. Add these functions. For more information about this step, see “Add Message Handlers for Person Menu Commands” on page 216 in Chapter 6.

7.Add message-handler functions for Help menu commands (Chapter 6).

Phone Book has two Help menu commands. Each command needs a handler defined as a member function of class CMainWindow and a corresponding entry in the message map of CMainWindow. You already added the handler function for the About menu command when you copied the Hello files to start Phone Book. Now add a function for the Help menu command. For more information about this step, see “Add Message Handlers for Help Menu Commands” on page 222 in Chapter 6.

8.Add message-handler functions for creation and sizing (Chapter 6).

Phone Book responds to a number of commonly handled Windows messages. These include WM_PAINT, WM_CREATE, and WM_SIZE. Add message-handler member functions to the CMainWindow class for these messages. For more information about this step, see “Add Message Handlers for Creation and Sizing” on page 224 in Chapter 6.

9.Add scrolling member functions (Chapter 6).

Phone Book handles both vertical and horizontal scrolling so the user can scroll through an entire database. For more information about this step, see “Add Scrolling Member Functions” on page 227 in Chapter 6.

10.Add a keyboard and mouse interface (Chapter 6).

Phone Book uses certain keystrokes and mouse clicks to set or change the selection in the window. You can use the UP ARROW and DOWN ARROW keys or the mouse to change the selection. You can also use the DELETE key to delete a selected person or the ENTER key to edit a selected person. In addition, you can click the mouse in the scroll bars to scroll the list of persons. These actions require handler functions as well. Add these handlers. For more information about this step, see “Add a Keyboard and Mouse Interface” on page 230 in Chapter 6.

11.Add a member function to handle the WM_PAINT message (Chapter 6).

The window that displays the database responds to this message to repaint its client area when it becomes invalid. For more information about this step, see “Add a Member Function to Handle the WM_PAINT Message” on page 235 in Chapter 6.

12.Add utility member functions (Chapter 6).

Phone Book uses several utility functions. These are main window member functions called by the main window object's message-handler functions. For more information on this step, see “Add Utility Member Functions” on page 238 in Chapter 6.

13.Prepare supporting files (Chapter 6).

As a Windows program, Phone Book requires the same kinds of supporting files as Hello. Add a module definition file, a resource script file, and a resource include file. For more information about this step, see “Prepare Supporting Files” on page 242 in Chapter 6.

14.Build the program (Chapter 6).

With all the files prepared, compile and link the program. Remember that you must run the program in Windows. For more information about this step, see “Build the Program” on page 243 in Chapter 6.

The sections and chapters that follow detail the procedures involved in each of these 14 steps. Any code related to a procedure is given within the text. Each section (except the following one) concludes with a discussion of what the code does and why it does it that way. Where appropriate, additional advanced discussion in a special box elaborates on the code and the basic discussion.