Opening and Saving Files with Common Dialog Boxes

The most frequently used common dialog boxes are those that open files and save files. As you can see in the example shown in Figure 6-2, these dia-log boxes support long filenames and contain a list view control, which graphically represents the contents of the current folder.

Figure 6-2.

An Open common dialog box in list view.

The Open common dialog box and the Save As common dialog box use the same dialog template, and you use the same structure, OPENFILENAME, to initialize them. The only real difference is how you display the dialog boxes: for opening a file, you use the GetOpenFileName function; for saving a file, you use the GetSaveFileName function.

The list view control in the Open or Save As common dialog box presents the current folder's contents in either list view or details view. Clicking the rightmost toolbar button changes the display to details view, which provides details about each object (file). For example, in the Save As dialog box shown in Figure 6-3 on the following page, you can see not only the object's name but also its size, its type, and when it was last modified. Clicking the next-to-last toolbar button on the right switches the display back to list view.

Figure 6-3.

A Save As common dialog box in details view.