Teach Yourself Visual C++ 5 in 21 Days

Chapter 5: Menus


Chapter 5 introduces you to a standard Windows feature: adding menus to your project. The objectives important to this chapter are:

  • adding a menu to a project
  • adding code to a menu

This project seems quite simplistic, but the purpose of adding a menu is twofold:

  • Menus are standard components of Windows applications, and an application without them would look and feel strange to the user.
  • Menus give the user keyboard control of events, a feature that is required in applications written to comply with reasonable accommodation issues.
The project begins in the expected way, creating a new workspace for a dialog based application. The changes begin on page 144.

A menu is a resource, as far as the project is concerned. To add it, think of the resource tree as a directory tree, and the menu folder (which you do not have yet) as a directory/folder that you want to add. In the resource view, right click on the top level folder. Choose the Insert option and you get a list of insertable object, like the list on page 145. Choose Menu from the list and click the New button to create a new Menu folder as a child of the top level folder.

As usual, creating this object does not give it the appearance we want, or set code in it. This is the creation of a skeleton object that you must flesh out.

On the next several pages, you add features to the menu. Be aware that it starts out with a blank rectangle, as on page 145, that represents the next menu choice you can create. I said next, not first, because there will always be a next item. As soon as you create one menu option, another blank rectangle appears for your possible use.

As you have done with buttons already, you will add ampersands to the captions of the menu choices, to enable hot keys for them.

The rest of this project is remarkably similar to your previous projects. You should have no trouble with it.