Saturday, 9 March 2013

Creating the Property Sheet Demo Application


Creating the Property Sheet Demo Application

Now that you've had an introduction to property sheets, it's time to learn how to build
an application that uses these handy specialized dialog boxes. You're about to build the
Property Sheet Demo application, which demonstrates the creation and manipulation of
property sheets. Follow the steps in the following sections to create the basic
application and modify its resources.
Creating the Basic Files
First, use AppWizard to create the basic files for the Property Sheet Demo program,
selecting the options listed in the following table. When you're done, the New Project

Information dialog box appears; it will look like Figure 12.2. Click OK to create the
project files.
Dialog Box Name Options to Select
New, Project tab Name the project Propsheet and then set the project path
to the directory in which you want to store the project's
files. Make sure that MFC AppWizard (exe) is highlighted.
Leave the other options set to their defaults.
Step 1 Select Single Document.
Step 2 of 6 Leave set to defaults.
Step 3 of 6 Leave set to defaults.
Step 4 of 6 Turn off all application features.
Step 5 of 6 Leave set to defaults.
Step 6 of 6 Leave set to defaults.
FIG. 12.2 Your New Project Information dialog box looks like this.
Editing the Resources
Now you'll edit the resources in the application generated for you by AppWizard,
removing unwanted menus and accelerators, editing the About box, and most
importantly, adding a menu item that will bring up a property sheet. Follow these steps:
1. Select the ResourceView tab in the project workspace window. Developer
Studio displays the ResourceView window (see Figure 12.3).
FIG. 12.3 The ResourceView tab displays the ResourceView window.
2. In the ResourceView window, click the plus sign next to Propsheet Resources to
display the application's resources. Click the plus sign next to Menu and then
double-click the IDR_MAINFRAME menu ID. Visual C++'s menu editor appears,
displaying the IDR_MAINFRAME menu generated by AppWizard.
3. Click the Property Sheet Demo application's Edit menu (not Visual C++'s Edit
menu) and then press Delete to delete the Edit menu. A dialog box asks for
verification of the Delete command; click OK.
4. Double-click the About Propsheet... item in the Help menu to bring up its
properties dialog box. Change the caption to &About Property Sheet Demo. Pin
the properties dialog box in place by clicking the pushpin in the upper-left corner.

5. On the application's File menu, delete all menu items except Exit.
6. Select the blank menu item at the end of the File menu, and change the caption
to &Property Sheet... and the command ID to ID_PROPSHEET (see Figure 12.4).
Then use your mouse to drag the new command above the Exit command so that it's
the first command in the File menu.
FIG. 12.4 Add a Property Sheet command to the File menu.
7. Click the + next to Accelerator in the ResourceView window and highlight the
IDR_MAINFRAME accelerator ID. Press Delete to delete all accelerators from
the application.
8. Click the + next to Dialog in the ResourceView window. Double-click the
IDD_ABOUTBOX dialog box ID to bring up the dialog box editor.
9. Modify the dialog box by clicking the title so that the properties box refers to
the whole dialog box. Change the caption to About Property Sheet Demo.
10. Click the first static text string and change the caption to Property Sheet
Demo, Version 1.0. Click the second and add Que Books to the end of the
copyright string.
11. Add a third static string with the text Special Edition Using Visual C++ 6 so
that your About box resembles the one in Figure 12.5. Close the dialog box editor.
12. Click the + next to String Table in the ResourceView window. Double-click
the String Table ID to bring up the string table editor.
13. Double-click the IDR_MAINFRAME string and then change the first segment
of the string to Property Sheet Demo (see Figure 12.6). The meanings of these
strings are discussed in Chapter 15, "Building an ActiveX Server Application," in
the "Shortcomings of This Server" section. The one you just changed is the
Window Title, used in the title bar of the application.
FIG. 12.5 The About box looks like this.
FIG. 12.6 The first segment of the IDR_MAINFRAME string appears in your main window's title bar.


No comments:

Post a Comment