Chapter 15. Working with Menus and Toolbars

WHAT YOU WILL LEARN IN THIS CHAPTER:

  • How an MFC-based program handles messages

  • Menu resources, and how you can create and modify them

  • Menu properties, and how you can create and modify them

  • How to create a function to service the message generated when a menu item is selected

  • How to add handlers to update menu properties

  • How to add toolbar buttons and associate them with existing menu items

In the last chapter, you saw how a simple framework application generated by the MFC Application Wizard is made up and how the parts interrelate. In this chapter, you'll start customizing a Multiple Document Interface (MDI) framework application called Sketcher with a view to making it into a useful program. The first step in this process is to understand how menus are defined in Visual C++ 2010, and how functions are created to service the application-specific menu items that you add to your program. You'll also see how to add toolbar buttons to the application.

COMMUNICATING WITH WINDOWS

As you saw in Chapter 12, Windows communicates with your program by sending messages to it. In an MFC application, most of the drudgery of message handling is taken care of, so you don't have to worry about providing a WndProc() function at all. MFC enables you to provide functions to handle just the individual messages that you're interested in and to ignore the rest. These functions are referred to as message handlers or just handlers. Because your application is MFC-based, ...

Get Ivor Horton's Beginning Visual C++® 2010 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.