[Previous] [Next]

Chapter 7


One of the ingredients found in the recipe for nearly every successful Microsoft Windows application is the control. A control is a special kind of window designed to convey information to the user or to acquire input. Most controls appear in dialog boxes, but they work just fine in top-level windows and other nondialog windows, too. The push button is one example of a control; the edit control—a simple rectangle for entering and editing text—is another.

Controls reduce the tedium of Windows programming and promote a consistent user interface by providing canned implementations of common user interface elements. Controls are prepackaged objects that come complete with their own window procedures. An application that uses a push button control doesn't have to draw the push button on the screen and process mouse messages to know when the push button is clicked. Instead, it creates the push button with a simple function call and receives notifications whenever the push button is clicked. The control's WM_PAINT handler paints the push button on the screen, and other message handlers inside the control translate user input into notification messages.

Controls are sometimes referred to as child window controls because of the parent-child relationships that they share with other windows. Unlike top-level windows, which have no parents, controls are child windows that are parented to other windows. A child window moves when its parent moves, is automatically destroyed when its parent is destroyed, and is clipped to its parent's window rectangle. And when a control transmits a notification message signifying an input event, its parent is the recipient of that message.

Current versions of Windows come with more than 20 types of controls. Six, which we'll refer to as the classic controls, have been around since the first version of Windows and are implemented in User.exe. The others, which are collectively known as the common controls, are relatively new to Windows (most debuted in Windows 95) and are implemented in Comctl32.dll. This chapter introduces the classic controls and the MFC classes that encapsulate them. The common controls are covered in Chapter 16.

The CHM file was converted to HTML by chm2web software.