📄 ch12.htm
字号:
<HTML>
<HEAD>
<TITLE>Special Edition Using Visual C++ 5 - Chapter 12</TITLE>
<LINK REL="Next" HREF="ch13.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/ch13.htm">
<LINK REL="Previous" HREF="ch11.htm" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/ch11.htm"></HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H2><B>Chapter 12</B></H2>
<H2><B>Property Pages and Sheets and Wizards</B></H2>
<hr>
<P>One of the newest types of graphical objects is the tabbed dialog box, also known as a <I>property sheet.</I> A property sheet is a dialog box with two or more pages. Windows 95 is loaded with property sheets, which organize the many options that can
be modified by the user. You flip the pages by clicking labeled tabs located at the top of the dialog box. By using such dialog boxes to organize complex groups of options, Windows 95 enables users to more easily find the information and settings that
they need. As you've probably guessed, Visual C++ 5.0 supports the Windows 95 property sheets, with the classes <font color="#008000">CPropertySheet</font> and <font color="#008000">CPropertyPage</font>.</P>
<P>Similar to property sheets are <I>wizards,</I> which use buttons to move from one page to another (rather than using tabs). You've seen a lot of wizards, too. These special types of dialog boxes guide the user step by step through complicated
processes. For example, when you use AppWizard to generate source code for a new project, the wizard guides you through the entire process. To control the wizard, you click buttons labeled Back, Next, and Finish.</P>
<ul>
<li> <B>How to create property page resources</B></P>
<P> Property sheets contain property pages, which are much like dialog boxes.</P>
<li> <B>How to associate property sheets and pages with their MFC </B><B>classes</B></P>
<P> MFC provides classes that enable you to easily manipulate property pages and property sheets.</P>
<li> <B>How to initialize and display property sheets</B></P>
<P> Creating a property sheet is only half the battle. You also have to get the sheet up on the screen for the user.</P>
<li> <B>How to convert a property sheet to a wizard</B></P>
<P> Wizards are a special type of property sheet. They guide users through complex tasks.</P>
<li> <B>How to respond to wizard buttons</B></P>
<P> Every wizard contains buttons that enable the user to navigate through the wizard.</P>
</ul>
<H3><B>Introducing Property Sheets</B></H3>
<P>Finding a sample property sheet in Windows 95 is as easy as finding sand at the beach. Just click virtually any Properties command or double-click an icon in the Control Panel. For example, Figure 12.1 shows the dialog box that you see when you
double-click the Control Panel's Add/Remove Programs icon. This is a property sheet that contains three pages labeled Install/Uninstall, Windows Setup, and Startup Disk. Each page contains commands and options related to the page's title topic.</P>
<A HREF="Nfigs01.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch12/Nfigs01.gif"><b>Fig. 12.1</b></A>
<P><I>The Add/Remove Programs Properties sheet contains three tabbed pages.</I></P>
<blockquote><p><img src="note.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/note.gif">
<P>Many people forget the difference between a property sheet and a property page. A <I>property sheet</I> is a window that contains property pages. <I>Property pages</I> are windows that hold controls. They appear on the property sheet's pages.</P>
<p><img src="bottom.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/bottom.gif"></blockquote>
<P>In Figure 12.1, you can see programs installed on your computer that Windows can automatically uninstall. There's also an Install button that leads to other dialog boxes that help you install new programs from floppy disk or CD-ROM. On the other hand,
the Windows Setup page (Figure 12.2) helps you add or remove files from the Windows system. To get to this page, you need only click the Windows Setup tab. The Startup Disk page, of course, houses yet another set of options.</P>
<A HREF="Nfigs02.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch12/Nfigs02.gif"><b>Fig. 12.2</b></A>
<P><I>Click the Windows Setup tab to move to the Windows Setup page.</I></P>
<P>As you can see, property sheets are a great way to organize many types of related options. Gone are the days of dialog boxes so jam-packed with options that you needed a college-level course just to figure them out. In the sections that follow, you
will learn to program your own tabbed property sheets using MFC's <font color="#008000">CPropertySheet</font> and <font color="#008000">CPropertyPage</font> classes.</P>
<H3><B>Creating the Property Sheet Demo Application</B></H3>
<P>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 are about to build the Property Sheet Demo application, which demonstrates the creation and
manipulation of property sheets. Follow these steps to create the basic application and modify its resources.</P>
<P>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 should look like Figure 12.3. Click the OK
button to create the project files.</P>
<TABLE BORDER>
<TR>
<TD>
<P><I>Dialog Box Name</I></P>
<TD>
<P><I>Options to Select</I></P>
<TR>
<TD>
<P>New, Project tab</P>
<TD>
<P>Name the project <font color="#008000">Propsheet</font> and then set the project path to the directory into which you want to store the project's files. Make sure MFC AppWizard (exe) is highlighted. Leave the other options set to their defaults.</P>
<TR>
<TD>
<P>Step 1</P>
<TD>
<P>Select Single Document.</P>
<TR>
<TD>
<P>Step 2 of 6</P>
<TD>
<P>Leave set to defaults.</P>
<TR>
<TD>
<P>Step 3 of 6</P>
<TD>
<P>Leave set to defaults.</P>
<TR>
<TD>
<P>Step 4 of 6</P>
<TD>
<P>Turn off all application features.</P>
<TR>
<TD>
<P>Step 5 of 6</P>
<TD>
<P>Leave set to defaults.</P>
<TR>
<TD>
<P>Step 6 of 6</P>
<TD>
<P>Leave set to defaults.</P></TABLE><br>
<A HREF="Nfigs03.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch12/Nfigs03.gif"><b>Fig. 12.3</b></A>
<P><I>Your Project Information dialog box should look like this.</I></P>
<P>Now you are going to 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:</P>
<ol>
<li><P> Select the ResourceView tab in the project workspace window. Developer Studio displays the ResourceView window, as shown in Figure 12.4.</P>
</ol>
<A HREF="Nfigs04.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch12/Nfigs04.gif"><b>Fig. 12.4</b></A>
<P><I>The ResourceView tab displays the ResourceView window.</I></P>
<ol start=2>
<li><P> In the ResourceView window, click the plus sign next to <font color="#008000">Propsheet resources</font> to display the application's resources. Click the plus sign next to Menu and then double-click the <font color="#008000">IDR_MAINFRAME</font>
menu ID. Visual C++'s menu editor appears, displaying the IDR_MAINFRAME menu generated by AppWizard.</P>
<li><P> Click the Property Sheet Demo application's <U>E</U>dit menu (not Visual C++'s Edit menu) and then press your keyboard's Delete key to delete the <U>E</U>dit menu. When you do, a dialog box asks for verification of the delete command. Click
OK.</P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -