?? ch12.htm
字號(hào):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function popUp(pPage) {
var fullURL = document.location;
var textURL = fullURL.toString();
var URLlen = textURL.length;
var lenMinusPage = textURL.lastIndexOf("/");
lenMinusPage += 1;
var fullPath = textURL.substring(0,lenMinusPage);
popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394');
figDoc= popUpWin.document;
zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>';
zhtm += '<link rel="stylesheet" href="/includes/stylesheets/ebooks.css"></head>';
zhtm += '<BODY bgcolor="#FFFFFF">';
zhtm += '<IMG SRC="' + fullPath + pPage + '">';
zhtm += '<P><B>' + pPage + '</B>';
zhtm += '</BODY></HTML>';
window.popUpWin.document.write(zhtm);
window.popUpWin.document.close();
// Johnny Jackson 4/28/98
}
//-->
</SCRIPT>
<link rel="stylesheet" href="/includes/stylesheets/ebooks.css">
<TITLE>Special Edition Using Visual C++ 6 -- Ch 12 -- Property Pages and Sheets</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
<CENTER>
<H1><IMG SRC="../button/que.gif" WIDTH="171" HEIGHT="66" ALIGN="BOTTOM" BORDER="0"><BR>
Special Edition Using Visual C++ 6</H1>
</CENTER>
<CENTER>
<P><A HREF="../ch11/ch11.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"
ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch13/ch13.htm"><IMG
SRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"
BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"
HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A>
<HR>
</CENTER>
<CENTER>
<H1>- 12 -</H1>
</CENTER>
<CENTER>
<H1>Property Pages and Sheets</H1>
</CENTER>
<UL>
<LI><A HREF="#Heading1">Introducing Property Sheets</A>
<LI><A HREF="#Heading2">Creating the Property Sheet Demo Application</A>
<UL>
<LI><A HREF="#Heading3">Creating the Basic Files</A>
<LI><A HREF="#Heading4">Editing the Resources</A>
<LI><A HREF="#Heading5">Adding New Resources</A>
<LI><A HREF="#Heading6">Associating Your Resources with Classes</A>
<LI><A HREF="#Heading7">Creating a Property Sheet Class</A>
</UL>
<LI><A HREF="#Heading8">Running the Property Sheet Demo Application</A>
<LI><A HREF="#Heading9">Adding Property Sheets to Your Applications</A>
<LI><A HREF="#Heading10">Changing Property Sheets to Wizards</A>
<UL>
<LI><A HREF="#Heading11">Running the Wizard Demo Application</A>
<LI><A HREF="#Heading12">Creating Wizard Pages</A>
<LI><A HREF="#Heading13">Displaying a Wizard</A>
<LI><A HREF="#Heading14">Setting the Wizard's Buttons</A>
<LI><A HREF="#Heading15">Responding to the Wizard's Buttons</A>
</UL>
</UL>
<P>
<HR SIZE="4">
<CENTER>
<H1></H1>
</CENTER>
<H2><A NAME="Heading1"></A>Introducing Property Sheets</H2>
<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 and NT are loaded with property sheets, which organize the many options that
users can modify. You flip the pages by clicking labeled tabs at the top of the dialog
box. Using such dialog boxes to organize complex groups of options enables users
to more easily find the information and settings they need. As you've probably guessed,
Visual C++ 6 supports property sheets, with the classes CPropertySheet and CPropertyPage.</P>
<P>Similar to property sheets are <I>wizards,</I> which use buttons instead of tabs
to move from one page to another. You've seen a lot of wizards, too. These special
types of dialog boxes guide users 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>
<P>Finding a sample property sheet is as easy as finding sand at the beach. Just
click virtually any Properties command or bring up an Options dialog in most applications.
For example, Figure 12.1 shows the dialog box that you see when you choose Tools,
Options from within Visual C++. This property sheet contains 12 pages in all, each
covering a different set of options.</P>
<P><A HREF="javascript:popUp('12uvc01.gif')"><B>FIG. 12.1</B></A><B> </B><I>The Options
properties sheet contains many tabbed pages.</I></P>
<P>
<BLOCKQUOTE>
<P>
<HR>
<strong>NOTE:</strong> 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. 
<HR>
</BLOCKQUOTE>
<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 following sections, you'll
learn to program your own tabbed property sheets by using MFC's CPropertySheet and
CPropertyPage classes.</P>
<P>
<H2><A NAME="Heading2"></A>Creating the Property Sheet Demo Application</H2>
<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'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.</P>
<P>
<H3><A NAME="Heading3"></A>Creating the Basic Files</H3>
<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 will look like Figure 12.2. Click OK to create
the project files.</P>
<P>
<TABLE BORDER="1">
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT"><B>Dialog Box Name</B></TD>
<TD ALIGN="LEFT"><B>Options to Select</B></TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">New, Project tab</TD>
<TD ALIGN="LEFT">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.</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">Step 1</TD>
<TD ALIGN="LEFT">Select Single Document.</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">Step 2 of 6</TD>
<TD ALIGN="LEFT">Leave set to defaults.</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">Step 3 of 6</TD>
<TD ALIGN="LEFT">Leave set to defaults.</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">Step 4 of 6</TD>
<TD ALIGN="LEFT">Turn off all application features.</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">Step 5 of 6</TD>
<TD ALIGN="LEFT">Leave set to defaults.</TD>
</TR>
<TR ALIGN="LEFT" VALIGN="TOP">
<TD ALIGN="LEFT">Step 6 of 6</TD>
<TD ALIGN="LEFT">Leave set to defaults.</TD>
</TR>
</TABLE>
</P>
<P><A HREF="javascript:popUp('12uvc02.gif')"><B>FIG. 12.2</B></A><B> </B><I>Your
New Project Information dialog box looks like this.</I></P>
<P>
<H3><A NAME="Heading4"></A>Editing the Resources</H3>
<P>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:</P>
<DL>
<DT></DT>
<DD><B>1. </B>Select the ResourceView tab in the project workspace window. Developer
Studio displays the ResourceView window (see Figure 12.3).
<P>
</DL>
<P><A HREF="javascript:popUp('12uvc03.gif')"><B>FIG. 12.3</B></A><B> </B><I>The ResourceView
tab displays the ResourceView window.</I></P>
<DL>
<DD><B>2. </B>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.
<P>
<DT></DT>
<DD><B>3. </B>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.
<P>
<DT></DT>
<DD><B>4. </B>Double-click the About Propsheet... item in the Help menu to bring
up its properties dialog box. Change the caption to <B>&About Property Sheet
Demo</B>. Pin the properties dialog box in place by clicking the pushpin in the upper-left
corner.
<P>
<DT></DT>
<DD><B>5. </B>On the application's File menu, delete all menu items except Exit.
<P>
<DT></DT>
<DD><B>6. </B>Select the blank menu item at the end of the File menu, and change
the caption to <B>&Property Sheet...</B> and the command ID to <B>ID_PROPSHEET</B>
(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.
<P>
</DL>
<P><A HREF="javascript:popUp('12uvc04.gif')"><B>FIG. 12.4</B></A><B> </B><I>Add a
Property Sheet command to the File menu.</I></P>
<P>
<DL>
<DD><B>7. </B>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.
<P>
<DT></DT>
<DD><B>8. </B>Click the + next to Dialog in the ResourceView window. Double-click
the IDD_ABOUTBOX dialog box ID to bring up the dialog box editor.
<P>
<DT></DT>
<DD><B>9. </B>Modify the dialog box by clicking the title so that the properties
box refers to the whole dialog box. Change the caption to<B> About Property Sheet
Demo</B>.
<P>
<DT></DT>
<DD><B>10. </B>Click the first static text string and change the caption to <B>Property
Sheet Demo, Version 1.0</B>. Click the second and add <B>Que Books</B> to the end
of the copyright string.
<P>
<DT></DT>
<DD><B>11. </B>Add a third static string with the text <B>Special Edition</B> <B>Using
Visual C++ 6</B> so that your About box resembles the one in Figure 12.5. Close the
dialog box editor.
<P>
<DT></DT>
<DD><B>12. </B>Click the + next to String Table in the ResourceView window. Double-click
the String Table ID to bring up the string table editor.
<P>
<DT></DT>
<DD><B>13. </B>Double-click the IDR_MAINFRAME string and then change the first segment
of the string to <B>Property Sheet Demo</B> (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.
<P>
</DL>
<P><A HREF="javascript:popUp('12uvc05.gif')"><B>FIG. 12.5</B></A><B> </B><I>The About
box looks like this.</I></P>
<P><A HREF="javascript:popUp('12uvc06.gif')"><B>FIG. 12.6</B></A><B> </B><I>The first
segment of the IDR_MAINFRAME string appears in your main window's title bar.</I></P>
<H3><I></I></H3>
<H3><A NAME="Heading5"></A>Adding New Resources</H3>
<P>Now that you have the application's basic resources the way you want them, it's
time to add the resources that define the application's property sheet. This means
creating dialog box resources for each page in the property sheet. Follow these steps:</P>
<DL>
<DT></DT>
<DD><B>1. </B>Click the New Dialog button on the Resource toolbar, or press Ctrl+1,
to create a new dialog box resource. The new dialog box, IDD_DIALOG1, appears in
the dialog box editor. This dialog box, when set up properly, will represent the
first page of the property sheet.
<P>
<DT></DT>
<DD><B>2. </B>Delete the OK and Cancel buttons by selecting each with your mouse
and then pressing Delete.
<P>
<DT></DT>
<DD><B>3. </B>If the Properties box isn't still up, bring it up by choosing View,
Properties. Change the ID of the dialog box to <B>IDD_PAGE1DLG</B> and the caption
to <B>Page 1</B> (see Figure 12.7).
<P>
</DL>
<P><A HREF="javascript:popUp('12uvc07.gif')"><B>FIG. 12.7</B></A><B> </B><I>Change
the caption and resource ID of the new dialog box.</I></P>
<DL>
<DD><B>4. </B>Click the Styles tab of the dialog box's property sheet. In the Style
drop-down box select Child, and in the Border drop-down box select Thin. Turn off
the System Menu check box. Your properties dialog box will resemble Figure 12.8.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -