Chapter Six: The New Common Dialog Boxes

The Win32 API supports common dialog boxes, which Microsoft Windows 95 provides to help the user perform functions that are common to most applications: opening and saving files, changing fonts, changing colors, searching for and replacing text, and printing. Not only do you save time by having the operating system carry out these mundane tasks, but you also automatically conform to the look and feel of the system when you include the common dialog boxes in your application.

These dialog boxes are easy to use. In the simplest case, when you want the dialog box's default appearance and behavior, you need only fill out a structure and call a single function. A dynamic-link library, COMDLG32.DLL, supplies the default dialog procedure and the default template for each common dialog box. If you want to extend the functionality of a dialog box, the system provides hooks and allows you to include your own template containing any additional controls that you need.

This chapter describes the various common dialog boxes and includes code examples that can help you incorporate these dialog boxes in your Win32-based applications. The examples come from CMNDLG32, a sample I wrote in C, which demonstrates how a developer can manipulate the common dialog boxes using their standard form or using hooks and custom templates. Figure 6-1, which appears on the following page, offers an advance look at the CMNDLG32 sample.

 

Figure 6-1.

The CMNDLG32 sample.

The new set of common dialog boxes found in Windows 95 has not only a fresh look but also some added functionality and a few other changes, as you'll see. But if you are an old hand at programming the common dialog boxes supported in Microsoft Windows version 3.1 and Microsoft Windows NT, you'll find that using the new dialog boxes requires little or no additional work. For example, the common dialog box sample I wrote for Windows NT many moons ago worked without a hitch under Windows 95, with no changes and no recompilation. If you are including templates and want to take advantage of the new look, a simple recompile is all you have to do. (If, however, you are including templates and don't want to change your dialog boxes, you don't have to do anything: just run the application, and your original dialog boxes will appear.)