The Hello Program

In the first part of this chapter, you will develop a simple Windows application using the Microsoft Foundation Classes. The example is a “Hello, World” program—the simple starter program familiar to all C programmers.

This section is an overview of what the program does and what you will be learning about the Microsoft Foundation Class Library.

What the Example Does

The example program displays the text “Hello, Windows!” centered in a window on the screen. The window has a menu bar and a set of window controls. If you choose the About command from the Help menu, a dialog box displays information about the program. You can drag the window around the screen or resize the window. If you resize the window, the text is recentered. You can minimize the window to an icon on the Windows desktop or maximize it to fill most of the screen.

Figure 3.1 shows the screen as it appears when Hello runs.

Although the example program does very little, it has a considerable amount of functionality with very little code. Furthermore, Hello makes a good template or skeleton on which to build more capable applications.

The Code for Hello

To view the complete code for Hello, see Listings 1 and 2. The code shown in these listings is available on the distribution disks in files HELLO.H and HELLO.CPP.

Microsoft Foundation Classes Used in This Chapter

This chapter demonstrates the use of five classes from the Microsoft Foundation Class Library.

CWinApp

You derive Hello's application class from this class.

CFrameWnd

You derive Hello's main window class from this class.

CRect

You pass a CRect object as an argument to a window-creation function. The argument specifies the rectangle in which the window is to be displayed.

CPaintDC

You construct an object of this class to create a Windows device context.

CModalDialog

You construct an object of this class to put a dialog box on the screen.

For more information about these classes, see the Class Libraries Reference and the discussion in this chapter.

The sections that follow take you through the components of Hello and explain how to write them, what they consist of, and in a general way how they work. A more detailed explanation of how they all work together is described in “How Hello Works” on page 110.