Chapter 3 Windows Programming with the Microsoft Foundation Classes

The previous chapter showed how to use the Microsoft Foundation Class Library to create a data model: a cooperating set of C++ objects that implements a simple database for storing CPerson objects.

This chapter shows how you can use the Microsoft Foundation Classes to create the key elements of a Microsoft Windows user interface. In order to use this chapter, and the next, you need to know something about Windows programming. Good sources for becoming familiar with Windows programming include the Programming Windows, Version 3.0, by Charles Petzold, and Microsoft Windows SDK Guide to Programming.

The purpose of this chapter is to show you how to use the Windows classes of the Microsoft Foundation Class Library to build applications that have a complete Windows user interface. The Microsoft Foundation Classes help you in two principal ways.

First, the Microsoft Foundation Class Library provides classes from which you can make objects that already have much of the Windows functionality you need. These classes include classes of windows, controls, dialogs, and graphics objects. The Microsoft Class Library also supplies class CWinApp, which provides most of the essential application-level processing your program needs. To create a Windows application, you use C++ techniques to derive both your own application class from class CWinApp and your own main window class from one of the class library's window classes.

Second, the Microsoft Foundation Class Library simplifies the message-handling apparatus of Windows. To process messages, you add a member function to your derived window class for each Windows message you want to handle. Then you place an entry in a “message map” for each message-processing member function.

The chapter demonstrates these techniques by taking you step by step through the development of a simple Windows application called Hello. As you go, you will see how to write the necessary C++ classes and what they do. After the examples have been developed, the chapter explains in greater detail how the Microsoft Foundation Classes work with Windows and your objects.