Chapter 10 Dialog Boxes

Dialog boxes are most often used for obtaining additional input from the user beyond what can be easily managed through a menu. The programmer indicates that a menu item invokes a dialog box by adding an ellipsis (...) to the menu item.

A dialog box generally takes the form of a popup window containing various child window controls. The size and placement of these controls are specified in a ”dialog box template“ in the program's resource script file. Windows is responsible for creating the dialog box popup window and the child window controls and for providing a window procedure to process dialog box messages (including all keyboard and mouse input). The code within Windows that does all this is sometimes referred to as the ”dialog box manager.“

Many of the messages that are processed by the dialog box window procedure within Windows are also passed to a function within your own program, called a ”dialog box procedure“ or ”dialog procedure.“ This function is similar to a normal window procedure, but with some important differences. Generally, you will not be doing very much within the dialog procedure except initializing the child window controls when the dialog box is created, processing messages from the child window controls, and ending the dialog box.

The subject of dialog boxes would normally be a big one, because it involves the use of child window controls. However, we have already explored child window controls in Chapter 6. When you use child window controls in dialog boxes, the Windows dialog box manager picks up many of the responsibilities that we assumed in Chapter 6. In particular, the problems we encountered with passing the input focus between the scroll bars in the COLORS1 program do not occur with dialog boxes. Windows handles all the logic necessary to shift input focus between controls in a dialog box.

However, adding a dialog box to a program is not a trivial undertaking. It involves changes to several files—the dialog box template goes in the resource script file, the dialog box procedure goes in the source code file, the name of the dialog box procedure goes in the module definition file, and identifiers used in the dialog box often go in the program's header file. We'll begin with a simple dialog box so that you get a feel for the interconnections between these various pieces.