Home Index  | Back

New Page 1
Lesson 1 -Building Your First Windows Application

1.1 : Creating a Windows Application

1.2 : Creating a Dialog-Based Application

1.3 : Creating DLLs, Console Applications, and More

1.4 : Changing Your AppWizard Decisions
 1.5 : Understanding AppWizard’s Code
 1.6 : Understanding a MDI Application
 1.7 : Understanding the Components of a Dialog-Based Application

Lesson 2 - Dialogs and Controls

2.1 : Understanding Dialog Boxes

2.2 : Creating a Dialog Box Resource

 2.3 : Writing a Dialog Box Class
 2.4 : Using the Dialog Box Class
Lesson 3 - Messages and Commands

3.1 : Understanding Message Routing

3.2 : Understanding Message Loops

 3.3 : Reading Message Maps
 3.4 : Learning How ClassWizard Helps You Catch Messages
 3.5 : Recognizing Messages
 3.6 : Understanding Commands
 3.7 : Understanding Command Updates
 3.8 : Learning How ClassWizard Helps You Catch Commands and Command Updates

Lesson 4 - Documents and Views

4.1 : Understanding the Document Class

4.2 : Understanding the View Class

4.3 : Creating the Rectangles Application

 4.4 : Other View Classes

4.5 : Document Templates, Views, and Frame Windows

Lesson 5 - Drawing on the Screen

5.1 :Understanding Device Contexts

 5.2 : Introducing the Paint1 Application
 5.3 : Building the Paint1 Application
 5.4 : Scrolling Windows
 5.5 : Building the Scroll Application
Lesson 6 - Building a Complete Application: ShowString

6.1 : Building an Application That Displays a String

 6.2 : Building the ShowString Menus
 6.3 : Building the ShowString Dialog Boxes
 6.4 : Making the Menu Work
 6.5 : Making the Dialog Box Work
 6.6 : Adding Appearance Options to the Options Dialog Box
Lesson 7 -  Status Bars and Toolbars

7.1 : Working with Toolbars

 7.2 : Working with Status Bars
Lesson 8 - Common Controls

8.1 : The Progress Bar Control

 8.2 : The Up-Down Control
 8.3 : The Image List Control
 8.4 : The List View Control
 8.5 : The Tree View Control
 8.6 : The Rich Edit Control
 8.7 : The Date Picker Control
 8.8 : Month Calendar Control
 8.9 : Scrolling the View
Lesson 9 - Property Pages and Sheets

9.1 : Introducing Property Sheets

 9.2 : Creating the Property Sheet Demo Application
 9.3 : Running the Property Sheet Demo Application
Lesson 10 - ActiveX Concepts

10.1 : The Purpose of ActiveX

10.2 : Object Linking

10.3 : Object Embedding

 10.4 : Containers and Servers
 10.5 : Toward a More Intuitive User Interface
 10.6 : The Component Object Model  

10.7 : Automation

 10.8 : ActiveX Controls

Lesson 11 -  Building an ActiveX Control

11.1 : Creating a Rolling-Die Control

11.2 : Displaying the Current Value

11.3 : Reacting to a Mouse Click and Rolling the Die 

 11.4 : Creating a Better User Interface
 11.5 : Generating Property Sheets
Lesson 12 - Database Access

12.1 : Understanding Database Concepts

12.2 : Creating an ODBC Database Program

 12.3 : Choosing Between ODBC and DAO
 12.4 : OLE DB

Lesson -9:Property Pages and Sheets

9.3- Running the Property Sheet Demo Application

You’ve finished the complete application. Click the Build button on the Build minibar (or choose Build, Build) to compile and link the application. Run it by choosing Build, Execute or by clicking the Execute button on the Build minibar. When you do, you see the window shown in Figure 9.9.

As you can see, the window displays two values—the default values for the controls in the application’s property sheet. You can change these values by using the property sheet. Choose File, Property Sheet; the property sheet appears (see Figure 9.10). The property sheet contains two pages, each of which holds a single control. When you change the settings of these controls and click the property sheet’s OK button, the application’s window displays the new values. Try it!


FIG. 9.9 When it first starts, the Property Sheet Demo application displays default values for the property sheet’s controls.


FIG. 9.10 The application’s property sheet contains two pages.

9.3.1 Adding Property Sheets to Your Applications

To add a property sheet to one of your own applications, you follow steps very similar to those you followed in the previous section to create the demo application:

1. Create a dialog box resource for each page in the property sheet. These resources should have the Child and Thin styles and should have no system menu.

2. Associate each property page resource with an object of the CPropertyPage class. You can do this easily with ClassWizard. Connect controls on the property page to members of the class you create.

3. Create a class for the property sheet, deriving the class from MFC’s CPropertySheet class. You can generate this class by using ClassWizard.

4. In the property sheet class, add member variables for each page you’ll be adding to the property sheet. These member variables must be instances of the property page classes that you created in step 2.

5. In the property sheet’s constructor, call AddPage() for each page in the property sheet.

6. To display the property sheet, call the property sheet’s constructor and then call the property sheet’s DoModal() member function, just as you would with a dialog box.

After you write your application and define the resources and classes that represent the property sheet (or sheets—you can have more than one), you need a way to enable users to display the property sheet when it’s needed. In Property Sheet Demo, this is done by associating a menu item with a message-response function. However you handle the command to display the property sheet, the process of creating the property sheet is the same. First, you must call the property sheet class’s constructor, which Property Sheet Demo does like this:

CPropSheet propSheet("Property Sheet", this, 0);

Here, the program creates an instance of the CPropSheet class. This instance (or object) is called propSheet. The three arguments are the property sheet’s title string, a pointer to the parent window (which, in this case, is the view window), and the zero-based index of the first page to display. Because the property pages are created in the property sheet’s constructor, creating the property sheet also creates the property pages.

After you create the property sheet object, you can initialize the data members that hold the values of the property page’s controls, which Property Sheet Demo does like this:

propSheet.m_page1.m_edit = m_edit;

propSheet.m_page2.m_check= m_check;

Now it’s time to display the property sheet, which you do just as though it were a dialog box, by calling the property sheet’s DoModal() member function:

int result = propSheet.DoModal();

DoModal() doesn’t take any arguments, but it does return a value indicating which button users clicked to exit the property sheet. In a property sheet or dialog box, you’ll usually want to process the information entered into the controls only if users clicked OK, which is indicated by a return value of IDOK. If users exit the property sheet by clicking the Cancel button, the changes are ignored and the view or document member variables aren’t updated.

MessageBox("You must check the box.");

return -1;

}

return CPropertyPage::OnWizardNext();

}

These functions demonstrate two ways to examine the check box on Page 2. OnWizardBack() gets a pointer to the page’s check box by calling the GetDlgItem() function. With the pointer in hand, the program can call the check box class’s GetCheck() function, which returns a 1 if the check box is checked. OnWizardNext() calls UpdateData() to fill all the CPage2 member variables with values from the dialog box controls and then looks at m_check. In both functions, if the box isn’t checked, the program displays a message box and returns -1 from the function. Returning -1 tells MFC to ignore the button click and not change pages. As you can see, it is simple to arrange for different conditions to leave the page in the Back or Next direction.

 

Next>>
 
© Dewsoft Overseas