Phase 2: Get Rid of Your Message-Handling Switch Statements

You now have an MFC C++ application created from your existing code base. The application already makes use of MFC to do more than it could originally, depending on the options you chose in AppWizard. But so far the application is not very tightly integrated with MFC; as a result, there are many MFC features it still can't take advantage of.

Note Phases 2 and 3 are optional. Consider them steps that add significant value to your application but that aren't strictly necessary. These steps have not been taken in the SHOWDIB sample application. Most are illustrated in the Scribble tutorial and other Visual C++ documentation and samples. See your C++ documentation.

In Phase 2, you'll continue to exploit the class structure of MFC, and you'll make use of the MFC message map mechanism. At the end of Phase 1, there are two large switch statements left in your migrated application. One is in WindowProc. The other is in OnCmdMsg. The goal of Phase 2 is to systematically remove both the WindowProc and OnCmdMsg function overrides, replacing them with message-mapped calls to class member functions designed to handle specific Windows-based messages.

Phase 2 steps include:

1. Using the MFC message map to handle Windows-based messages.

2. Using MFC's menu update mechanism to update the state of menus (and other user interface objects, such as toolbar buttons).

3. Using class member variables to replace using the cbWndExtra and cbClsExtra members of the WNDCLASS structure, in which Windows-based programmers usually store application-specific information.