Ivor Horton's Beginning Visual C++®2008

Book description

Proudly presenting the latest edition of one of the all-time bestselling books on the C++ language, successful author Ivor Horton repeats the formula that has made each previous edition so popular by teaching you both the standard C++ language and C++/CLI as well as Visual C++ 2008. Thoroughly updated for the 2008 release, this book shows you how to build real-world applications using Visual C++ and guides you through the ins and outs of C++ development. With this book by your side, you are well on your way to becoming a successful C++ programmer.

Table of contents

  1. Copyright
  2. About the Author
  3. Acknowledgments
  4. Credits
  5. Introduction
    1. Whom This Book Is For
    2. What This Book Covers
    3. How This Book Is Structured
    4. What You Need to Use This Book
    5. Using the Windows Classic Theme
    6. Conventions
        1. How It Works
    7. Source Code
    8. Errata
    9. p2p.wrox.com
  6. 1. Programming with Visual C++ 2008
    1. 1.1. The .NET Framework
    2. 1.2. The Common Language Runtime (CLR)
    3. 1.3. Writing C++ Applications
    4. 1.4. Learning Windows Programming
      1. 1.4.1. Learning C++
      2. 1.4.2. The C++ Standards
      3. 1.4.3. Attributes
      4. 1.4.4. Console Applications
      5. 1.4.5. Windows Programming Concepts
    5. 1.5. What Is the Integrated Development Environment?
      1. 1.5.1. Components of the System
        1. 1.5.1.1. The Editor
        2. 1.5.1.2. The Compiler
        3. 1.5.1.3. The Linker
        4. 1.5.1.4. The Libraries
    6. 1.6. Using the IDE
      1. 1.6.1. Toolbar Options
      2. 1.6.2. Dockable Toolbars
      3. 1.6.3. Documentation
      4. 1.6.4. Projects and Solutions
        1. 1.6.4.1. Defining a Project
          1. 1.6.4.1.1. Modifying the Source Code
          2. 1.6.4.1.2. Building the Solution
          3. 1.6.4.1.3. Files Created by Building a Console Application
        2. 1.6.4.2. Debug and Release Versions of Your Program
          1. 1.6.4.2.1. Executing the Program
        3. 1.6.4.3. Dealing with Errors
      5. 1.6.5. Setting Options in Visual C++ 2008
      6. 1.6.6. Creating and Executing Windows Applications
        1. 1.6.6.1. Creating an MFC Application
        2. 1.6.6.2. Building and Executing the MFC Application
      7. 1.6.7. Creating a Windows Forms Application
    7. 1.7. Summary
  7. 2. Data, Variables, and Calculations
    1. 2.1. The Structure of a C++ Program
      1. 2.1.1.
        1. 2.1.1.1. Program Comments
        2. 2.1.1.2. The #include Directive—Header Files
        3. 2.1.1.3. Namespaces and the Using Declaration
      2. 2.1.2. The main() Function
      3. 2.1.3. Program Statements
      4. 2.1.4. Whitespace
      5. 2.1.5. Statement Blocks
      6. 2.1.6. Automatically Generated Console Programs
    2. 2.2. Defining Variables
      1. 2.2.1. Naming Variables
        1. 2.2.1.1. Keywords in C++
      2. 2.2.2. Declaring Variables
      3. 2.2.3. Initial Values for Variables
    3. 2.3. Fundamental Data Types
      1. 2.3.1. Integer Variables
      2. 2.3.2. Character Data Types
      3. 2.3.3. Integer Type Modifiers
      4. 2.3.4. The Boolean Type
      5. 2.3.5. Floating-Point Types
        1. 2.3.5.1. Fundamental Types in ISO/ANSI C++
      6. 2.3.6. Literals
      7. 2.3.7. Defining Synonyms for Data Types
      8. 2.3.8. Variables with Specific Sets of Values
    4. 2.4. Basic Input/Output Operations
      1. 2.4.1. Input from the Keyboard
      2. 2.4.2. Output to the Command Line
        1. 2.4.2.1. How It Works
      3. 2.4.3. Formatting the Output
        1. 2.4.3.1. How It Works
      4. 2.4.4. Escape Sequences
        1. 2.4.4.1. How It Works
    5. 2.5. Calculating in C++
      1. 2.5.1. The Assignment Statement
        1. 2.5.1.1. Understanding Lvalues and Rvalues
      2. 2.5.2. Arithmetic Operations
        1. 2.5.2.1. How It Works
        2. 2.5.2.2. The const Modifier
        3. 2.5.2.3. Constant Expressions
        4. 2.5.2.4. Program Input
        5. 2.5.2.5. Calculating the Result
        6. 2.5.2.6. Displaying the Result
      3. 2.5.3. Calculating a Remainder
      4. 2.5.4. Modifying a Variable
      5. 2.5.5. The Increment and Decrement Operators
        1. 2.5.5.1. How It Works
      6. 2.5.6. The Sequence of Calculation
        1. 2.5.6.1. Operator Precedence
    6. 2.6. Variable Types and Casting
      1. 2.6.1. Rules for Casting Operands
      2. 2.6.2. Casts in Assignment Statements
      3. 2.6.3. Explicit Casts
      4. 2.6.4. Old-Style Casts
    7. 2.7. The Bitwise Operators
      1. 2.7.1. The Bitwise AND
      2. 2.7.2. The Bitwise OR
      3. 2.7.3. The Bitwise Exclusive OR
      4. 2.7.4. The Bitwise NOT
      5. 2.7.5. The Bitwise Shift Operators
    8. 2.8. Understanding Storage Duration and Scope
      1. 2.8.1. Automatic Variables
        1. 2.8.1.1. How It Works
      2. 2.8.2. Positioning Variable Declarations
      3. 2.8.3. Global Variables
        1. 2.8.3.1. How It Works
      4. 2.8.4. Static Variables
    9. 2.9. Namespaces
      1. 2.9.1. Declaring a Namespace
      2. 2.9.2. Multiple Namespaces
    10. 2.10. C++/CLI Programming
      1. 2.10.1. C++/CLI Specific: Fundamental Data Types
        1. 2.10.1.1. How It Works
      2. 2.10.2. C++/CLI Output to the Command Line
      3. 2.10.3. C++/CLI Specific—Formatting the Output
        1. 2.10.3.1. How It Works
      4. 2.10.4. C++/CLI Input from the Keyboard
      5. 2.10.5. Using safe_cast
      6. 2.10.6. C++/CLI Enumerations
        1. 2.10.6.1. How It Works
        2. 2.10.6.2. Specifying a Type for Enumeration Constants
        3. 2.10.6.3. Specifying Values for Enumeration Constants
        4. 2.10.6.4. Operations on Enumeration Constants
        5. 2.10.6.5. Using Enumerators as Flags
        6. 2.10.6.6. Native Enumerations in a C++/CLI Program
    11. 2.11. Summary
    12. 2.12. Exercises
  8. 3. Decisions and Loops
    1. 3.1. Comparing Values
      1. 3.1.1. The if Statement
      2. 3.1.2. Nested if Statements
        1. 3.1.2.1. How It Works
        2. 3.1.2.2. The Extended if Statement
        3. 3.1.2.3. How It Works
      3. 3.1.3. Nested if-else Statements
      4. 3.1.4. Logical Operators and Expressions
        1. 3.1.4.1. Logical AND
        2. 3.1.4.2. Logical OR
        3. 3.1.4.3. Logical NOT
        4. 3.1.4.4. How It Works
      5. 3.1.5. The Conditional Operator
        1. 3.1.5.1. How It Works
      6. 3.1.6. The switch Statement
        1. 3.1.6.1. How It Works
        2. 3.1.6.2. How It Works
      7. 3.1.7. Unconditional Branching
    2. 3.2. Repeating a Block of Statements
      1. 3.2.1. What Is a Loop?
        1. 3.2.1.1. How It Works
      2. 3.2.2. Variations on the for Loop
        1. 3.2.2.1. How It Works
        2. 3.2.2.2. How It Works
        3. 3.2.2.3. Using the continue Statement
        4. 3.2.2.4. How It Works
        5. 3.2.2.5. Floating-Point Loop Counters
      3. 3.2.3. The while Loop
        1. 3.2.3.1. How It Works
      4. 3.2.4. The do-while Loop
      5. 3.2.5. Nested Loops
        1. 3.2.5.1. How It Works
        2. 3.2.5.2. How It Works
    3. 3.3. C++/CLI Programming
      1. 3.3.1.
        1. 3.3.1.1. How It Works
        2. 3.3.1.2. How It Works
      2. 3.3.2. The for each Loop
        1. 3.3.2.1. How It Works
    4. 3.4. Summary
    5. 3.5. Exercises
  9. 4. Arrays, Strings, and Pointers
    1. 4.1. Handling Multiple Data Values of the Same Type
      1. 4.1.1. Arrays
      2. 4.1.2. Declaring Arrays
        1. 4.1.2.1. How It Works
        2. 4.1.2.2. Entering the Data
        3. 4.1.2.3. Producing the Results
      3. 4.1.3. Initializing Arrays
        1. 4.1.3.1. How It Works
      4. 4.1.4. Character Arrays and String Handling
        1. 4.1.4.1. String Input
        2. 4.1.4.2. How It Works
      5. 4.1.5. Multidimensional Arrays
        1. 4.1.5.1. Initializing Multidimensional Arrays
        2. 4.1.5.2. How It Works
    2. 4.2. Indirect Data Access
      1. 4.2.1. What Is a Pointer?
      2. 4.2.2. Declaring Pointers
        1. 4.2.2.1. The Address-Of Operator
      3. 4.2.3. Using Pointers
        1. 4.2.3.1. The Indirection Operator
        2. 4.2.3.2. Why Use Pointers?
        3. 4.2.3.3. How It Works
      4. 4.2.4. Initializing Pointers
        1. 4.2.4.1. Pointers to char
        2. 4.2.4.2. How It Works
        3. 4.2.4.3. How It Works
      5. 4.2.5. The sizeof Operator
        1. 4.2.5.1. How It Works
      6. 4.2.6. Constant Pointers and Pointers to Constants
      7. 4.2.7. Pointers and Arrays
        1. 4.2.7.1. Pointer Arithmetic
        2. 4.2.7.2. How It Works
        3. 4.2.7.3. How It Works
        4. 4.2.7.4. Using Pointers with Multidimensional Arrays
        5. 4.2.7.5. Pointer Notation with Multidimensional Arrays
    3. 4.3. Dynamic Memory Allocation
      1. 4.3.1. The Free Store, Alias the Heap
      2. 4.3.2. The new and delete Operators
      3. 4.3.3. Allocating Memory Dynamically for Arrays
        1. 4.3.3.1. How It Works
      4. 4.3.4. Dynamic Allocation of Multidimensional Arrays
    4. 4.4. Using References
      1. 4.4.1. What Is a Reference?
      2. 4.4.2. Declaring and Initializing References
    5. 4.5. Native C++ Library Functions for Strings
      1. 4.5.1. Finding the Length of a Null-Terminated String
      2. 4.5.2. Joining Null-Terminated Strings
      3. 4.5.3. Copying Null-Terminated Strings
      4. 4.5.4. Comparing Null-Terminated Strings
      5. 4.5.5. Searching Null-Terminated Strings
        1. 4.5.5.1. How It Works
    6. 4.6. C++/CLI Programming
      1. 4.6.1. Tracking Handles
        1. 4.6.1.1. Declaring Tracking Handles
      2. 4.6.2. CLR Arrays
        1. 4.6.2.1. How It Works
        2. 4.6.2.2. Sorting One-Dimensional Arrays
        3. 4.6.2.3. How It Works
        4. 4.6.2.4. Searching One-Dimensional Arrays
        5. 4.6.2.5. How It Works
        6. 4.6.2.6. Multidimensional Arrays
        7. 4.6.2.7. How It Works
        8. 4.6.2.8. Arrays of Arrays
        9. 4.6.2.9. How It Works
      3. 4.6.3. Strings
        1. 4.6.3.1. Joining Strings
        2. 4.6.3.2. How It Works
        3. 4.6.3.3. Modifying Strings
        4. 4.6.3.4. Comparing Strings
        5. 4.6.3.5. Searching Strings
        6. 4.6.3.6. How It Works
      4. 4.6.4. Tracking References
      5. 4.6.5. Interior Pointers
        1. 4.6.5.1. How It Works
    7. 4.7. Summary
    8. 4.8. Exercises
  10. 5. Introducing Structure into Your Programs
    1. 5.1. Understanding Functions
      1. 5.1.1. Why Do You Need Functions?
      2. 5.1.2. Structure of a Function
        1. 5.1.2.1. The Function Header
          1. 5.1.2.1.1. The General Form of a Function Header
        2. 5.1.2.2. The Function Body
        3. 5.1.2.3. The return Statement
      3. 5.1.3. Using a Function
        1. 5.1.3.1. Function Prototypes
        2. 5.1.3.2. How It Works
    2. 5.2. Passing Arguments to a Function
      1. 5.2.1. The Pass-by-value Mechanism
        1. 5.2.1.1. How It Works
      2. 5.2.2. Pointers as Arguments to a Function
        1. 5.2.2.1. How It Works
      3. 5.2.3. Passing Arrays to a Function
        1. 5.2.3.1. How It Works
        2. 5.2.3.2. How It Works
        3. 5.2.3.3. Passing Multidimensional Arrays to a Function
        4. 5.2.3.4. How It Works
      4. 5.2.4. References as Arguments to a Function
        1. 5.2.4.1. How It Works
      5. 5.2.5. Use of the const Modifier
        1. 5.2.5.1. How It Works
      6. 5.2.6. Arguments to main()
        1. 5.2.6.1. How It Works
      7. 5.2.7. Accepting a Variable Number of Function Arguments
        1. 5.2.7.1. How It Works
    3. 5.3. Returning Values from a Function
      1. 5.3.1. Returning a Pointer
        1. 5.3.1.1. How It Works (or Why It Doesn't)
        2. 5.3.1.2. A Cast Iron Rule for Returning Addresses
      2. 5.3.2. Returning a Reference
        1. 5.3.2.1. How It Works
        2. 5.3.2.2. A Teflon-Coated Rule: Returning References
      3. 5.3.3. Static Variables in a Function
        1. 5.3.3.1. How It Works
    4. 5.4. Recursive Function Calls
      1. 5.4.1.
        1. 5.4.1.1. How It Works
      2. 5.4.2. Using Recursion
    5. 5.5. C++/CLI Programming
      1. 5.5.1. Functions Accepting a Variable Number of Arguments
        1. 5.5.1.1. How It Works
      2. 5.5.2. Arguments to main()
        1. 5.5.2.1. How It Works
    6. 5.6. Summary
    7. 5.7. Exercises
  11. 6. More about Program Structure
    1. 6.1. Pointers to Functions
      1. 6.1.1. Declaring Pointers to Functions
        1. 6.1.1.1. How It Works
      2. 6.1.2. A Pointer to a Function as an Argument
        1. 6.1.2.1. How It Works
      3. 6.1.3. Arrays of Pointers to Functions
    2. 6.2. Initializing Function Parameters
      1. 6.2.1.
        1. 6.2.1.1. How It Works
    3. 6.3. Exceptions
      1. 6.3.1.
        1. 6.3.1.1. How It Works
      2. 6.3.2. Throwing Exceptions
      3. 6.3.3. Catching Exceptions
        1. 6.3.3.1. How It Works
      4. 6.3.4. Exception Handling in the MFC
    4. 6.4. Handling Memory Allocation Errors
      1. 6.4.1.
        1. 6.4.1.1. How It Works
    5. 6.5. Function Overloading
      1. 6.5.1. What Is Function Overloading?
        1. 6.5.1.1. How It Works
      2. 6.5.2. When to Overload Functions
    6. 6.6. Function Templates
      1. 6.6.1. Using a Function Template
        1. 6.6.1.1. How It Works
    7. 6.7. An Example Using Functions
      1. 6.7.1. Implementing a Calculator
        1. 6.7.1.1. Analyzing the Problem
      2. 6.7.2. Eliminating Blanks from a String
        1. 6.7.2.1. How the Function Functions
      3. 6.7.3. Evaluating an Expression
        1. 6.7.3.1. How the Function Functions
      4. 6.7.4. Getting the Value of a Term
        1. 6.7.4.1. How the Function Functions
      5. 6.7.5. Analyzing a Number
        1. 6.7.5.1. How the Function Functions
      6. 6.7.6. Putting the Program Together
        1. 6.7.6.1. How the Function Functions
      7. 6.7.7. Extending the Program
        1. 6.7.7.1. How the Function Functions
      8. 6.7.8. Extracting a Substring
        1. 6.7.8.1. How the Function Functions
      9. 6.7.9. Running the Modified Program
    8. 6.8. C++/CLI Programming
      1. 6.8.1. Understanding Generic Functions
        1. 6.8.1.1. Defining Generic Functions
        2. 6.8.1.2. Using Generic Functions
        3. 6.8.1.3. How It Works
      2. 6.8.2. A Calculator Program for the CLR
        1. 6.8.2.1. Removing Spaces from the Input String
        2. 6.8.2.2. Evaluating an Arithmetic Expression
        3. 6.8.2.3. Obtaining the Value of a Term
        4. 6.8.2.4. Evaluating a Number
        5. 6.8.2.5. Extracting a Parenthesized Substring
    9. 6.9. Summary
    10. 6.10. Exercises
  12. 7. Defining Your Own Data Types
    1. 7.1. The struct in C++
      1. 7.1.1. What Is a struct?
      2. 7.1.2. Defining a struct
      3. 7.1.3. Initializing a struct
      4. 7.1.4. Accessing the Members of a struct
        1. 7.1.4.1. How It Works
      5. 7.1.5. IntelliSense Assistance with Structures
      6. 7.1.6. The struct RECT
      7. 7.1.7. Using Pointers with a struct
        1. 7.1.7.1. Accessing Structure Members through a Pointer
        2. 7.1.7.2. The Indirect Member Selection Operator
    2. 7.2. Data Types, Objects, Classes, and Instances
      1. 7.2.1. First Class
      2. 7.2.2. Operations on Classes
      3. 7.2.3. Terminology
    3. 7.3. Understanding Classes
      1. 7.3.1. Defining a Class
        1. 7.3.1.1. Access Control in a Class
      2. 7.3.2. Declaring Objects of a Class
      3. 7.3.3. Accessing the Data Members of a Class
        1. 7.3.3.1. How It Works
      4. 7.3.4. Member Functions of a Class
        1. 7.3.4.1. How It Works
      5. 7.3.5. Positioning a Member Function Definition
      6. 7.3.6. Inline Functions
    4. 7.4. Class Constructors
      1. 7.4.1. What Is a Constructor?
        1. 7.4.1.1. How It Works
      2. 7.4.2. The Default Constructor
        1. 7.4.2.1. How It Works
      3. 7.4.3. Assigning Default Parameter Values in a Class
        1. 7.4.3.1. How It Works
      4. 7.4.4. Using an Initialization List in a Constructor
    5. 7.5. Private Members of a Class
      1. 7.5.1.
        1. 7.5.1.1. How It Works
      2. 7.5.2. Accessing private Class Members
      3. 7.5.3. The friend Functions of a Class
        1. 7.5.3.1. How It Works
        2. 7.5.3.2. Placing friend Function Definitions Inside the Class
      4. 7.5.4. The Default Copy Constructor
        1. 7.5.4.1. How It Works
    6. 7.6. The Pointer this
      1. 7.6.1.
        1. 7.6.1.1. How It Works
    7. 7.7. const Objects of a Class
      1. 7.7.1. const Member Functions of a Class
      2. 7.7.2. Member Function Definitions Outside the Class
    8. 7.8. Arrays of Objects of a Class
      1. 7.8.1.
        1. 7.8.1.1. How It Works
    9. 7.9. Static Members of a Class
      1. 7.9.1. Static Data Members of a Class
        1. 7.9.1.1. How It Works
      2. 7.9.2. Static Function Members of a Class
    10. 7.10. Pointers and References to Class Objects
      1. 7.10.1. Pointers to Class Objects
        1. 7.10.1.1. How It Works
      2. 7.10.2. References to Class Objects
        1. 7.10.2.1. Implementing a Copy Constructor
    11. 7.11. C++/CLI Programming
      1. 7.11.1. Defining Value Class Types
        1. 7.11.1.1. How It Works
        2. 7.11.1.2. The ToString() Function in a Class
        3. 7.11.1.3. Literal Fields
      2. 7.11.2. Defining Reference Class Types
        1. 7.11.2.1. How It Works
      3. 7.11.3. Defining a Copy Constructor for a Reference Class Type
      4. 7.11.4. Class Properties
        1. 7.11.4.1. Defining Scalar Properties
        2. 7.11.4.2. Trivial Scalar Properties
        3. 7.11.4.3. How It Works
        4. 7.11.4.4. Defining Indexed Properties
        5. 7.11.4.5. How It Works
        6. 7.11.4.6. More Complex Indexed Properties
        7. 7.11.4.7. Static Properties
        8. 7.11.4.8. Reserved Property Names
      5. 7.11.5. initonly Fields
      6. 7.11.6. Static Constructors
    12. 7.12. Summary
    13. 7.13. Exercises
  13. 8. More on Classes
    1. 8.1. Class Destructors
      1. 8.1.1. What Is a Destructor?
      2. 8.1.2. The Default Destructor
        1. 8.1.2.1. How It Works
      3. 8.1.3. Destructors and Dynamic Memory Allocation
        1. 8.1.3.1. How It Works
    2. 8.2. Implementing a Copy Constructor
    3. 8.3. Sharing Memory Between Variables
      1. 8.3.1. Defining Unions
      2. 8.3.2. Anonymous Unions
      3. 8.3.3. Unions in Classes and Structures
    4. 8.4. Operator Overloading
      1. 8.4.1. Implementing an Overloaded Operator
        1. 8.4.1.1. How It Works
      2. 8.4.2. Implementing Full Support for a Comparison Operator
        1. 8.4.2.1. How It Works
      3. 8.4.3. Overloading the Assignment Operator
        1. 8.4.3.1. Fixing the Problem
      4. 8.4.4. Overloading the Addition Operator
        1. 8.4.4.1. How It Works
      5. 8.4.5. Overloading the Increment and Decrement Operators
    5. 8.5. Class Templates
      1. 8.5.1. Defining a Class Template
        1. 8.5.1.1. Template Member Functions
      2. 8.5.2. Creating Objects from a Class Template
      3. 8.5.3. Class Templates with Multiple Parameters
    6. 8.6. Using Classes
      1. 8.6.1. The Idea of a Class Interface
      2. 8.6.2. Defining the Problem
      3. 8.6.3. Implementing the CBox Class
        1. 8.6.3.1. Comparing CBox Objects
        2. 8.6.3.2. Combining CBox Objects
        3. 8.6.3.3. Analyzing CBox Objects
        4. 8.6.3.4. Defining the CBox Class
        5. 8.6.3.5. Adding Data Members
        6. 8.6.3.6. Defining the Constructor
        7. 8.6.3.7. Adding Function Members
        8. 8.6.3.8. Adding Global Functions
        9. 8.6.3.9. Using Our CBox Class
        10. 8.6.3.10. How It Works
    7. 8.7. Organizing Your Program Code
      1. 8.7.1. Naming Program Files
    8. 8.8. Native C++ Library Classes for Strings
      1. 8.8.1. Creating String Objects
      2. 8.8.2. Concatenating Strings
        1. 8.8.2.1. How It Works
      3. 8.8.3. Accessing and Modifying Strings
      4. 8.8.4. Comparing Strings
        1. 8.8.4.1. How It Works
      5. 8.8.5. Searching Strings
        1. 8.8.5.1. How It Works
    9. 8.9. C++/CLI Programming
      1. 8.9.1. Overloading Operators in Value Classes
        1. 8.9.1.1. How It Works
      2. 8.9.2. Overloading the Increment and Decrement Operators
      3. 8.9.3. Overloading Operators in Reference Classes
        1. 8.9.3.1. How It Works
      4. 8.9.4. Implementing the Assignment Operator for Reference Types
    10. 8.10. Summary
    11. 8.11. Exercises
  14. 9. Class Inheritance and Virtual Functions
    1. 9.1. Basic Ideas of OOP
    2. 9.2. Inheritance in Classes
      1. 9.2.1. What Is a Base Class?
      2. 9.2.2. Deriving Classes from a Base Class
        1. 9.2.2.1. How It Works
    3. 9.3. Access Control Under Inheritance
      1. 9.3.1.
        1. 9.3.1.1. How It Works
      2. 9.3.2. Constructor Operation in a Derived Class
        1. 9.3.2.1. How It Works
      3. 9.3.3. Declaring Class Members to Be Protected
        1. 9.3.3.1. How It Works
      4. 9.3.4. The Access Level of Inherited Class Members
    4. 9.4. The Copy Constructor in a Derived Class
      1. 9.4.1.
        1. 9.4.1.1. How It Works (or Why It Doesn't)
        2. 9.4.1.2. How It Works
    5. 9.5. Class Members as Friends
      1. 9.5.1. Friend Classes
      2. 9.5.2. Limitations on Class Friendship
    6. 9.6. Virtual Functions
      1. 9.6.1.
        1. 9.6.1.1. How It Works
      2. 9.6.2. What Is a Virtual Function?
        1. 9.6.2.1. How It Works
      3. 9.6.3. Using Pointers to Class Objects
        1. 9.6.3.1. How It Works
      4. 9.6.4. Using References with Virtual Functions
        1. 9.6.4.1. How It Works
        2. 9.6.4.2. Incomplete Class Definitions
      5. 9.6.5. Pure Virtual Functions
      6. 9.6.6. Abstract Classes
        1. 9.6.6.1. How It Works
      7. 9.6.7. Indirect Base Classes
        1. 9.6.7.1. How It Works
      8. 9.6.8. Virtual Destructors
        1. 9.6.8.1. How It Works
    7. 9.7. Casting Between Class Types
    8. 9.8. Nested Classes
      1. 9.8.1.
        1. 9.8.1.1. How It Works
    9. 9.9. C++/CLI Programming
      1. 9.9.1. Boxing and Unboxing
      2. 9.9.2. Inheritance in C++/CLI Classes
        1. 9.9.2.1. How It Works
      3. 9.9.3. Interface Classes
      4. 9.9.4. Defining Interface Classes
        1. 9.9.4.1. How It Works
      5. 9.9.5. Classes and Assemblies
        1. 9.9.5.1. Visibility Specifiers for Classes and Interfaces
        2. 9.9.5.2. Access Specifiers for Class and Interface Members
      6. 9.9.6. Functions Specified as new
      7. 9.9.7. Delegates and Events
        1. 9.9.7.1. Declaring Delegates
        2. 9.9.7.2. Creating Delegates
        3. 9.9.7.3. How It Works
        4. 9.9.7.4. Unbound Delegates
        5. 9.9.7.5. How It Works
        6. 9.9.7.6. Creating Events
        7. 9.9.7.7. How It Works
      8. 9.9.8. Destructors and Finalizers in Reference Classes
        1. 9.9.8.1. How It Works
      9. 9.9.9. Generic Classes
        1. 9.9.9.1. How It Works
        2. 9.9.9.2. Generic Interface Classes
        3. 9.9.9.3. Generic Collection Classes
          1. 9.9.9.3.1. List—A Generic List
          2. 9.9.9.3.2. LinkedList<T>—A Generic Doubly Linked List
          3. 9.9.9.3.3. Dictionary<TKey, TValue>—A Generic Dictionary Storing Key/Value Pairs
        4. 9.9.9.4. How It Works
    10. 9.10. Summary
    11. 9.11. Exercises
  15. 10. The Standard Template Library
    1. 10.1. What Is the Standard Template Library?
      1. 10.1.1. Containers
      2. 10.1.2. Container Adapters
      3. 10.1.3. Iterators
      4. 10.1.4. Algorithms
      5. 10.1.5. Function Objects
      6. 10.1.6. Function Adapters
    2. 10.2. The Range of STL Containers
    3. 10.3. Sequence Containers
      1. 10.3.1. Creating Vector Containers
      2. 10.3.2. The Capacity and Size of a Vector Container
        1. 10.3.2.1. How It Works
      3. 10.3.3. Accessing the Elements in a Vector
      4. 10.3.4. Inserting and Deleting Elements in a Vector
      5. 10.3.5. Storing Class Objects in a Vector
        1. 10.3.5.1. How It Works
      6. 10.3.6. Sorting Vector Elements
      7. 10.3.7. Storing Pointers in a Vector
        1. 10.3.7.1. How It Works
      8. 10.3.8. Double-Ended Queue Containers
        1. 10.3.8.1. How It Works
      9. 10.3.9. Using List Containers
        1. 10.3.9.1. Adding Elements to a List
        2. 10.3.9.2. Accessing Elements in a List
        3. 10.3.9.3. How It Works
        4. 10.3.9.4. Other Operations on Lists
        5. 10.3.9.5. How It Works
      10. 10.3.10. Using Other Sequence Containers
        1. 10.3.10.1. Queue Containers
        2. 10.3.10.2. How It Works
        3. 10.3.10.3. Priority Queue Containers
        4. 10.3.10.4. How It Works
        5. 10.3.10.5. Stack Containers
        6. 10.3.10.6. How It Works
    4. 10.4. Associative Containers
      1. 10.4.1. Using Map Containers
        1. 10.4.1.1. Storing Objects
        2. 10.4.1.2. Accessing Objects
        3. 10.4.1.3. Other Map Operations
        4. 10.4.1.4. How It Works
      2. 10.4.2. Using a Multimap Container
    5. 10.5. More on Iterators
      1. 10.5.1. Using Input Stream Iterators
        1. 10.5.1.1. How It Works
      2. 10.5.2. Using Inserter Iterators
      3. 10.5.3. Using Output Stream Iterators
        1. 10.5.3.1. How It Works
    6. 10.6. More on Function Objects
    7. 10.7. More on Algorithms
      1. 10.7.1. fill()
      2. 10.7.2. replace()
      3. 10.7.3. find()
      4. 10.7.4. transform()
    8. 10.8. The STL for C++/CLI Programs
      1. 10.8.1. STL/CLR Containers
      2. 10.8.2. Using Sequence Containers
        1. 10.8.2.1. How It Works
        2. 10.8.2.2. How It Works
        3. 10.8.2.3. How It Works
      3. 10.8.3. Using Associative Containers
        1. 10.8.3.1. How It Works
    9. 10.9. Summary
    10. 10.10. Exercises
  16. 11. Debugging Techniques
    1. 11.1. Understanding Debugging
      1. 11.1.1. Program Bugs
      2. 11.1.2. Common Bugs
    2. 11.2. Basic Debugging Operations
      1. 11.2.1. Setting Breakpoints
        1. 11.2.1.1. Advanced Breakpoints
      2. 11.2.2. Setting Tracepoints
      3. 11.2.3. Starting Debugging
        1. 11.2.3.1. Inspecting Variable Values
        2. 11.2.3.2. Viewing Variables in the Edit Window
      4. 11.2.4. Changing the Value of a Variable
    3. 11.3. Adding Debugging Code
      1. 11.3.1. Using Assertions
      2. 11.3.2. Adding Your Own Debugging Code
        1. 11.3.2.1. How It Works
    4. 11.4. Debugging a Program
      1. 11.4.1. The Call Stack
      2. 11.4.2. Step Over to the Error
    5. 11.5. Testing the Extended Class
      1. 11.5.1. Finding the Next Bug
    6. 11.6. Debugging Dynamic Memory
      1. 11.6.1. Functions Checking the Free Store
      2. 11.6.2. Controlling Free Store Debug Operations
      3. 11.6.3. Free Store Debugging Output
        1. 11.6.3.1. How It Works
    7. 11.7. Debugging C++/CLI Programs
      1. 11.7.1. Using the Debug and Trace Classes
        1. 11.7.1.1. Generating Output
        2. 11.7.1.2. Setting the Output Destination
        3. 11.7.1.3. Indenting the Output
        4. 11.7.1.4. Controlling Output
        5. 11.7.1.5. Assertions
        6. 11.7.1.6. How It Works
      2. 11.7.2. Getting Trace Output in Windows Forms Applications
    8. 11.8. Summary
  17. 12. Windows Programming Concepts
    1. 12.1. Windows Programming Basics
      1. 12.1.1. Elements of a Window
      2. 12.1.2. Windows Programs and the Operating System
      3. 12.1.3. Event-Driven Programs
      4. 12.1.4. Windows Messages
      5. 12.1.5. The Windows API
      6. 12.1.6. Windows Data Types
      7. 12.1.7. Notation in Windows Programs
    2. 12.2. The Structure of a Windows Program
      1. 12.2.1. The WinMain() Function
        1. 12.2.1.1. Specifying a Program Window
        2. 12.2.1.2. Creating a Program Window
        3. 12.2.1.3. Initializing the Program Window
        4. 12.2.1.4. Dealing with Windows Messages
          1. 12.2.1.4.1. Queued and Non-Queued Messages
          2. 12.2.1.4.2. The Message Loop
          3. 12.2.1.4.3. Multitasking
        5. 12.2.1.5. A Complete WinMain() Function
        6. 12.2.1.6. How It Works
      2. 12.2.2. Message Processing Functions
        1. 12.2.2.1. The WindowProc() Function
        2. 12.2.2.2. Decoding a Windows Message
          1. 12.2.2.2.1. Drawing the Window Client Area
        3. 12.2.2.3. Ending the Program
        4. 12.2.2.4. A Complete WindowProc() Function
        5. 12.2.2.5. How It Works
      3. 12.2.3. A Simple Windows Program
    3. 12.3. Windows Program Organization
    4. 12.4. The Microsoft Foundation Classes
      1. 12.4.1. MFC Notation
      2. 12.4.2. How an MFC Program Is Structured
        1. 12.4.2.1. The Application Class
        2. 12.4.2.2. The Window Class
        3. 12.4.2.3. Completing the Program
        4. 12.4.2.4. The Finished Product
        5. 12.4.2.5. How It Works
    5. 12.5. Using Windows Forms
      1. 12.5.1.
        1. 12.5.1.1. How It Works
    6. 12.6. Summary
  18. 13. Windows Programming with the Microsoft Foundation Classes
    1. 13.1. The Document/View Concept in MFC
      1. 13.1.1. What Is a Document?
      2. 13.1.2. Document Interfaces
      3. 13.1.3. What Is a View?
      4. 13.1.4. Linking a Document and Its Views
        1. 13.1.4.1. Document Templates
        2. 13.1.4.2. Document Template Classes
      5. 13.1.5. Your Application and MFC
    2. 13.2. Creating MFC Applications
      1. 13.2.1. Creating an SDI Application
      2. 13.2.2. The Output from the MFC Application Wizard
        1. 13.2.2.1. Viewing Project Files
        2. 13.2.2.2. Viewing Classes
        3. 13.2.2.3. The Class Definitions
        4. 13.2.2.4. Creating an Executable Module
          1. 13.2.2.4.1. Precompiled Header Files
        5. 13.2.2.5. Running the Program
        6. 13.2.2.6. How the Program Works
          1. 13.2.2.6.1. The InitInstance() Function
          2. 13.2.2.6.2. The Run() Function
      3. 13.2.3. Creating an MDI Application
        1. 13.2.3.1. Running the Program
    3. 13.3. Summary
    4. 13.4. Exercises
  19. 14. Working with Menus and Toolbars
    1. 14.1. Communicating with Windows
      1. 14.1.1. Understanding Message Maps
        1. 14.1.1.1. Message Handler Definitions
      2. 14.1.2. Message Categories
      3. 14.1.3. Handling Messages in Your Program
        1. 14.1.3.1. How Command Messages Are Processed
    2. 14.2. Extending the Sketcher Program
    3. 14.3. Elements of a Menu
      1. 14.3.1. Creating and Editing Menu Resources
        1. 14.3.1.1. Adding a Menu Item to the Menu Bar
        2. 14.3.1.2. Adding Items to the Element Menu
        3. 14.3.1.3. Modifying Existing Menu Items
        4. 14.3.1.4. Completing the Menu
    4. 14.4. Adding Handlers for Menu Messages
      1. 14.4.1. Choosing a Class to Handle Menu Messages
      2. 14.4.2. Creating Menu Message Functions
      3. 14.4.3. Coding Menu Message Functions
        1. 14.4.3.1. Adding Members to Store Color and Element Mode
        2. 14.4.3.2. Initializing the New Class Data Members
          1. 14.4.3.2.1. Modifying the Class Constructor
        3. 14.4.3.3. Running the Extended Example
      4. 14.4.4. Adding Message Handlers to Update the User Interface
        1. 14.4.4.1. Coding a Command Update Handler
        2. 14.4.4.2. Exercising the Update Handlers
    5. 14.5. Adding Toolbar Buttons
      1. 14.5.1. Editing Toolbar Button Properties
      2. 14.5.2. Exercising the Toolbar Buttons
      3. 14.5.3. Adding Tooltips
    6. 14.6. Menu and Toolbars in a C++/CLI Program
      1. 14.6.1. Understanding Windows Forms
      2. 14.6.2. Understanding Windows Forms Applications
        1. 14.6.2.1. Modifying the Properties of a Form
        2. 14.6.2.2. How the Application Starts
      3. 14.6.3. Adding a Menu to CLR Sketcher
      4. 14.6.4. Adding Event Handlers for Menu Items
      5. 14.6.5. Implementing Event Handlers
      6. 14.6.6. Setting Menu Item Checks
      7. 14.6.7. Adding a Toolbar
    7. 14.7. Summary
    8. 14.8. Exercises
  20. 15. Drawing in a Window
    1. 15.1. Basics of Drawing in a Window
      1. 15.1.1. The Window Client Area
      2. 15.1.2. The Windows Graphical Device Interface
        1. 15.1.2.1. What Is a Device Context?
        2. 15.1.2.2. Mapping Modes
    2. 15.2. The Drawing Mechanism in Visual C++
      1. 15.2.1. The View Class in Your Application
        1. 15.2.1.1. The OnDraw() Member Function
      2. 15.2.2. The CDC Class
        1. 15.2.2.1. Displaying Graphics
          1. 15.2.2.1.1. Drawing Lines
          2. 15.2.2.1.2. Drawing Circles
        2. 15.2.2.2. Drawing in Color
          1. 15.2.2.2.1. Creating a Pen
          2. 15.2.2.2.2. Using a Pen
          3. 15.2.2.2.3. Creating a Brush
          4. 15.2.2.2.4. Using a Brush
    3. 15.3. Drawing Graphics in Practice
    4. 15.4. Programming the Mouse
      1. 15.4.1. Messages from the Mouse
        1. 15.4.1.1. WM_LBUTTONDOWN
        2. 15.4.1.2. WM_MOUSEMOVE
        3. 15.4.1.3. WM_LBUTTONUP
      2. 15.4.2. Mouse Message Handlers
      3. 15.4.3. Drawing Using the Mouse
        1. 15.4.3.1. Getting the Client Area Redrawn
        2. 15.4.3.2. Defining Classes for Elements
          1. 15.4.3.2.1. Storing a Temporary Element in the View
        3. 15.4.3.3. The CElement Class
        4. 15.4.3.4. The CLine Class
          1. 15.4.3.4.1. Implementing the CLine Class
          2. 15.4.3.4.2. The CLine Class Constructor
          3. 15.4.3.4.3. Drawing a Line
          4. 15.4.3.4.4. Creating Bounding Rectangles
          5. 15.4.3.4.5. Normalized Rectangles
        5. 15.4.3.5. Calculating the Enclosing Rectangle for a Line
        6. 15.4.3.6. The CRectangle Class
          1. 15.4.3.6.1. The CRectangle Class Constructor
          2. 15.4.3.6.2. Drawing a Rectangle
        7. 15.4.3.7. The CCircle Class
          1. 15.4.3.7.1. Implementing the CCircle Class
          2. 15.4.3.7.2. The CCircle Class Constructor
          3. 15.4.3.7.3. Drawing a Circle
        8. 15.4.3.8. The CCurve Class
        9. 15.4.3.9. Completing the Mouse Message Handlers
          1. 15.4.3.9.1. Setting the Drawing Mode
          2. 15.4.3.9.2. Coding the OnMouseMove() Handler
          3. 15.4.3.9.3. Creating an Element
          4. 15.4.3.9.4. Dealing with WM_LBUTTONUP Messages
    5. 15.5. Exercising Sketcher
      1. 15.5.1. Running the Example
      2. 15.5.2. Capturing Mouse Messages
    6. 15.6. Drawing with the CLR
      1. 15.6.1. Drawing on a Form
      2. 15.6.2. Adding Mouse Event Handlers
      3. 15.6.3. Defining C++/CLI Element Classes
        1. 15.6.3.1. Defining a Line
          1. 15.6.3.1.1. Defining a Color
          2. 15.6.3.1.2. Drawing Lines
          3. 15.6.3.1.3. Defining a Pen for Drawing
          4. 15.6.3.1.4. Standard Pens
        2. 15.6.3.2. Defining a Rectangle
        3. 15.6.3.3. Defining a Circle
      4. 15.6.4. Implementing the MouseMove Event Handler
      5. 15.6.5. Implementing the MouseUp Event Handler
      6. 15.6.6. Implementing the Paint Event Handler for the Form
    7. 15.7. Summary
    8. 15.8. Exercises
  21. 16. Creating the Document and Improving the View
    1. 16.1. The MFC Collection Classes
      1. 16.1.1. Types of Collection
      2. 16.1.2. The Type-Safe Collection Classes
      3. 16.1.3. Collections of Objects
        1. 16.1.3.1. The CArray Template Class
        2. 16.1.3.2. Helper Functions
        3. 16.1.3.3. The CList Template Class
          1. 16.1.3.3.1. Adding Elements to a List
          2. 16.1.3.3.2. Iterating through a List
          3. 16.1.3.3.3. Searching a List
          4. 16.1.3.3.4. Deleting Objects from a List
          5. 16.1.3.3.5. Helper Functions for a List
        4. 16.1.3.4. The CMap Template Class
          1. 16.1.3.4.1. Helper Functions Used by CMap
      4. 16.1.4. The Typed Pointer Collections
        1. 16.1.4.1. The CTypedPtrList Template Class
        2. 16.1.4.2. CTypePtrList Operations
    2. 16.2. Using the CList Template Class
      1. 16.2.1. Drawing a Curve
      2. 16.2.2. Defining the CCurve Class
      3. 16.2.3. Implementing the CCurve Class
      4. 16.2.4. Exercising the CCurve Class
    3. 16.3. Creating the Sketch Document
      1. 16.3.1. Using a CTypedPtrList Template
        1. 16.3.1.1. Implementing the Document Destructor
        2. 16.3.1.2. Drawing the Document
        3. 16.3.1.3. Adding an Element to the Document
        4. 16.3.1.4. Exercising the Document
    4. 16.4. Improving the View
      1. 16.4.1. Updating Multiple Views
      2. 16.4.2. Scrolling Views
        1. 16.4.2.1. Logical Coordinates and Client Coordinates
        2. 16.4.2.2. Dealing with Client Coordinates
      3. 16.4.3. Using MM_LOENGLISH Mapping Mode
    5. 16.5. Deleting and Moving Shapes
    6. 16.6. Implementing a Context Menu
      1. 16.6.1. Associating a Menu with a Class
      2. 16.6.2. Choosing a Context Menu
        1. 16.6.2.1. Identifying a Selected Element
        2. 16.6.2.2. Exercising the Pop-Ups
        3. 16.6.2.3. Checking the Context Menu Items
      3. 16.6.3. Highlighting Elements
        1. 16.6.3.1. Drawing Highlighted Elements
        2. 16.6.3.2. Exercising the Highlights
      4. 16.6.4. Servicing the Menu Messages
        1. 16.6.4.1. Deleting an Element
        2. 16.6.4.2. Moving an Element
          1. 16.6.4.2.1. Modifying the WM_MOUSEMOVE Handler
        3. 16.6.4.3. Getting the Elements to Move Themselves
          1. 16.6.4.3.1. Dropping the Element
        4. 16.6.4.4. Exercising the Application
    7. 16.7. Dealing with Masked Elements
    8. 16.8. Extending CLRSketcher
      1. 16.8.1. Coordinate System Transformations
      2. 16.8.2. Defining a Curve
      3. 16.8.3. Defining a Sketch Class
      4. 16.8.4. Drawing the Sketch in the Paint Event Handler
      5. 16.8.5. Implementing Element Highlighting
      6. 16.8.6. Creating Context Menus
        1. 16.8.6.1. Implementing the Element Delete Operation
        2. 16.8.6.2. Implementing the Send-To-Back operation
        3. 16.8.6.3. Implementing the Element Move Operation
        4. 16.8.6.4. Moving an Element
    9. 16.9. Summary
    10. 16.10. Exercises
  22. 17. Working with Dialogs and Controls
    1. 17.1. Understanding Dialogs
    2. 17.2. Understanding Controls
      1. 17.2.1. Common Controls
    3. 17.3. Creating a Dialog Resource
      1. 17.3.1. Adding Controls to a Dialog Box
        1. 17.3.1.1. Testing the Dialog
    4. 17.4. Programming for a Dialog
      1. 17.4.1. Adding a Dialog Class
      2. 17.4.2. Modal and Modeless Dialogs
      3. 17.4.3. Displaying a Dialog
        1. 17.4.3.1. Code to Display the Dialog
        2. 17.4.3.2. Code to Close the Dialog
    5. 17.5. Supporting the Dialog Controls
      1. 17.5.1. Initializing the Controls
      2. 17.5.2. Handling Radio Button Messages
    6. 17.6. Completing Dialog Operations
      1. 17.6.1. Adding Pen Widths to the Document
      2. 17.6.2. Adding Pen Widths to the Elements
      3. 17.6.3. Creating Elements in the View
      4. 17.6.4. Exercising the Dialog
    7. 17.7. Using a Spin Button Control
      1. 17.7.1. Adding the Scale Menu Item and Toolbar Button
      2. 17.7.2. Creating the Spin Button
        1. 17.7.2.1. The Controls' Tab Sequence
      3. 17.7.3. Generating the Scale Dialog Class
        1. 17.7.3.1. Dialog Data Exchange and Validation
        2. 17.7.3.2. Initializing the Dialog
      4. 17.7.4. Displaying the Spin Button
    8. 17.8. Using the Scale Factor
      1. 17.8.1. Scaleable Mapping Modes
      2. 17.8.2. Setting the Document Size
      3. 17.8.3. Setting the Mapping Mode
      4. 17.8.4. Implementing Scrolling with Scaling
        1. 17.8.4.1. Setting Up the Scrollbars
    9. 17.9. Working with Status Bars
      1. 17.9.1. Adding a Status Bar to a Frame
        1. 17.9.1.1. Defining the Status Bar Parts
        2. 17.9.1.2. Updating the Status Bar
    10. 17.10. Using a List Box
      1. 17.10.1. Removing the Scale Dialog
      2. 17.10.2. Creating a List Box Control
        1. 17.10.2.1. Creating the Dialog Class
        2. 17.10.2.2. Displaying the Dialog
    11. 17.11. Using an Edit Box Control
      1. 17.11.1. Creating an Edit Box Resource
      2. 17.11.2. Creating the Dialog Class
        1. 17.11.2.1. The CString Class
      3. 17.11.3. Adding the Text Menu Item
      4. 17.11.4. Defining a Text Element
      5. 17.11.5. Implementing the CText Class
        1. 17.11.5.1. The CText Constructor
        2. 17.11.5.2. Drawing a CText Object
        3. 17.11.5.3. Moving a CText Object
      6. 17.11.6. Creating a Text Element
    12. 17.12. Dialogs and Controls in CLR Sketcher
      1. 17.12.1. Adding a Dialog
        1. 17.12.1.1. Customizing the Dialog
        2. 17.12.1.2. Displaying the Dialog
        3. 17.12.1.3. Setting the Drawing Pen Width
        4. 17.12.1.4. Using a Combo Box Control
      2. 17.12.2. Creating Text Elements
        1. 17.12.2.1. Drawing Text
          1. 17.12.2.1.1. Creating Fonts
          2. 17.12.2.1.2. Creating Brushes
        2. 17.12.2.2. Choosing a Font
        3. 17.12.2.3. Defining the Text Element Class
        4. 17.12.2.4. Creating the Text Dialog
          1. 17.12.2.4.1. Using a Text Box
          2. 17.12.2.4.2. Displaying the Dialog and Creating a Text Element
    13. 17.13. Summary
    14. 17.14. Exercises
  23. 18. Storing and Printing Documents
    1. 18.1. Understanding Serialization
    2. 18.2. Serializing a Document
      1. 18.2.1. Serialization in the Document Class Definition
      2. 18.2.2. Serialization in the Document Class Implementation
        1. 18.2.2.1. The Serialize() Function
        2. 18.2.2.2. The CArchive Class
      3. 18.2.3. Functionality of CObject-Based Classes
        1. 18.2.3.1. The Macros Adding Serialization to a Class
      4. 18.2.4. How Serialization Works
      5. 18.2.5. How to Implement Serialization for a Class
    3. 18.3. Applying Serialization
      1. 18.3.1. Recording Document Changes
      2. 18.3.2. Serializing the Document
      3. 18.3.3. Serializing the Element Classes
        1. 18.3.3.1. The Serialize() Functions for the Shape Classes
    4. 18.4. Exercising Serialization
    5. 18.5. Moving Text
    6. 18.6. Printing a Document
      1. 18.6.1. The Printing Process
        1. 18.6.1.1. The CPrintInfo Class
    7. 18.7. Implementing Multipage Printing
      1. 18.7.1. Getting the Overall Document Size
      2. 18.7.2. Storing Print Data
      3. 18.7.3. Preparing to Print
      4. 18.7.4. Cleaning Up After Printing
      5. 18.7.5. Preparing the Device Context
      6. 18.7.6. Printing the Document
      7. 18.7.7. Getting a Printout of the Document
    8. 18.8. Serialization and Printing in CLR Sketcher
      1. 18.8.1. Understanding Binary Serialization
        1. 18.8.1.1. Dealing with Fields That Are Not Serializable
        2. 18.8.1.2. Serializing an Object
      2. 18.8.2. Serializing a Sketch
        1. 18.8.2.1. Making the Sketch Class Serializable
        2. 18.8.2.2. Implementing File Operations for a Sketch
          1. 18.8.2.2.1. Creating Dialogs for File Operations
          2. 18.8.2.2.2. Saving a Sketch
          3. 18.8.2.2.3. Retrieving a Sketch from a File
          4. 18.8.2.2.4. Implementing the Save As Operation
      3. 18.8.3. Printing a Sketch
        1. 18.8.3.1. Using the PrintDocument Component
        2. 18.8.3.2. Implementing the Print Operation
    9. 18.9. Summary
    10. 18.10. Exercises
  24. 19. Writing Your Own DLLs
    1. 19.1. Understanding DLLs
      1. 19.1.1. How DLLs Work
        1. 19.1.1.1. Runtime Dynamic Linking
      2. 19.1.2. Contents of a DLL
        1. 19.1.2.1. The DLL Interface
        2. 19.1.2.2. The DllMain() Function
      3. 19.1.3. DLL Varieties
        1. 19.1.3.1. MFC Extension DLL
        2. 19.1.3.2. Regular DLL—Statically Linked to MFC
        3. 19.1.3.3. Regular DLL—Dynamically Linked to MFC
    2. 19.2. Deciding What to Put in a DLL
    3. 19.3. Writing DLLs
      1. 19.3.1. Writing and Using an Extension DLL
        1. 19.3.1.1. Understanding DllMain()
        2. 19.3.1.2. Adding Classes to the Extension DLL
        3. 19.3.1.3. Exporting Classes from the Extension DLL
        4. 19.3.1.4. Building a DLL
        5. 19.3.1.5. Using the Extension DLL in Sketcher
        6. 19.3.1.6. Files Required to Use a DLL
      2. 19.3.2. Exporting Variables and Functions from a DLL
      3. 19.3.3. Importing Symbols into a Program
      4. 19.3.4. Implementing the Export of Symbols from a DLL
        1. 19.3.4.1. Using Exported Symbols
    4. 19.4. Summary
    5. 19.5. Exercises
  25. 20. Connecting to Data Sources
    1. 20.1. Database Basics
    2. 20.2. A Little SQL
      1. 20.2.1. Retrieving Data Using SQL
        1. 20.2.1.1. Choosing Records
      2. 20.2.2. Joining Tables Using SQL
      3. 20.2.3. Sorting Records
    3. 20.3. Database Support in MFC
      1. 20.3.1. MFC Classes Supporting ODBC
    4. 20.4. Creating a Database Application
      1. 20.4.1. Registering an ODBC Database
      2. 20.4.2. Generating an MFC ODBC Program
        1. 20.4.2.1. Snapshot versus Dynaset Recordsets
      3. 20.4.3. Understanding the Program Structure
        1. 20.4.3.1. Understanding Recordsets
          1. 20.4.3.1.1. Recordset Creation
          2. 20.4.3.1.2. Querying the Database
          3. 20.4.3.1.3. Data Transfer between the Database and the Recordset
        2. 20.4.3.2. Understanding the Record View
        3. 20.4.3.3. Creating the View Dialog
        4. 20.4.3.4. Linking the Controls to the Recordset
      4. 20.4.4. Exercising the Example
    5. 20.5. Sorting a Recordset
      1. 20.5.1. Modifying the Window Caption
    6. 20.6. Using a Second Recordset Object
      1. 20.6.1. Adding a Recordset Class
      2. 20.6.2. Adding a View Class for the Recordset
        1. 20.6.2.1. Creating the Dialog Resource
        2. 20.6.2.2. Creating the Record View Class
      3. 20.6.3. Customizing the Recordset
        1. 20.6.3.1. Adding a Filter to the Recordset
        2. 20.6.3.2. Defining the Filter Parameter
        3. 20.6.3.3. Initializing the Record View
      4. 20.6.4. Accessing Multiple Table Views
        1. 20.6.4.1. Switching Views
        2. 20.6.4.2. Enabling the Switching Operation
        3. 20.6.4.3. Handling View Activation
      5. 20.6.5. Viewing Orders for a Product
    7. 20.7. Viewing Customer Details
      1. 20.7.1. Adding the Customer Recordset
      2. 20.7.2. Creating the Customer Dialog Resource
      3. 20.7.3. Creating the Customer View Class
      4. 20.7.4. Adding a Filter
      5. 20.7.5. Implementing the Filter Parameter
      6. 20.7.6. Linking the Order Dialog to the Customer Dialog
      7. 20.7.7. Exercising the Database Viewer
    8. 20.8. Summary
    9. 20.9. Exercises
  26. 21. Updating Data Sources
    1. 21.1. Update Operations
      1. 21.1.1. CRecordset Update Operations
        1. 21.1.1.1. Checking that Operations are Legal
        2. 21.1.1.2. Record Locking
      2. 21.1.2. Transactions
        1. 21.1.2.1. CDatabase Transaction Operations
    2. 21.2. A Simple Update Example
      1. 21.2.1. Customizing the Application
        1. 21.2.1.1. How It Works
    3. 21.3. Managing the Update Process
      1. 21.3.1. Implementing Update Mode
        1. 21.3.1.1. Enabling and Disabling Edit Controls
        2. 21.3.1.2. Changing the Button Label
        3. 21.3.1.3. Controlling the Visibility of the Cancel Button
        4. 21.3.1.4. Disabling the Record Menu
        5. 21.3.1.5. Expediting the Update
        6. 21.3.1.6. Implementing the Cancel Operation
    4. 21.4. Adding Rows to a Table
      1. 21.4.1. The Order Entry Process
      2. 21.4.2. Creating the Resources
      3. 21.4.3. Creating the Recordsets
      4. 21.4.4. Creating the Recordset Views
      5. 21.4.5. Adding Controls to the Dialog Resources
      6. 21.4.6. Implementing Dialog Switching
      7. 21.4.7. Creating an Order ID
        1. 21.4.7.1. Storing the New Order ID
        2. 21.4.7.2. Creating the New Order ID
        3. 21.4.7.3. Initiating ID Creation
      8. 21.4.8. Storing the Order Data
        1. 21.4.8.1. Setting Dates
      9. 21.4.9. Selecting Products for an Order
      10. 21.4.10. Adding a New Order
    5. 21.5. Summary
    6. 21.6. Exercises
  27. 22. More on Windows Forms Applications
    1. 22.1. Creating the Application GUI
      1. 22.1.1. Adding Submenus
      2. 22.1.2. Adding a Tab Control
      3. 22.1.3. Using GroupBox Controls
      4. 22.1.4. Using Button Controls
      5. 22.1.5. Using the WebBrowser Control
      6. 22.1.6. Operation of the Winning Application
      7. 22.1.7. Adding a Context Menu
      8. 22.1.8. Creating Event Handlers
        1. 22.1.8.1. Event Handlers for Menu Items
        2. 22.1.8.2. Adding Members to the Form1 Class
        3. 22.1.8.3. Handling the Play Menu Event
      9. 22.1.9. Handling Events for the Limits Menu
      10. 22.1.10. Creating a Dialog Box
        1. 22.1.10.1. Adding a List to a ListBox
        2. 22.1.10.2. Handling the Dialog Button Events
        3. 22.1.10.3. Controlling the State of the ListBox Objects
        4. 22.1.10.4. Creating the Dialog Object
      11. 22.1.11. Using the Dialog Box
        1. 22.1.11.1. Validating the Input
        2. 22.1.11.2. Handling the Reset Menu Item Event
      12. 22.1.12. Adding the Second Dialog
        1. 22.1.12.1. Getting the Data from the Dialog Controls
        2. 22.1.12.2. Disabling Input Controls
        3. 22.1.12.3. Updating the Limits Menu Item Handlers
      13. 22.1.13. Implementing the Help > About Menu Item
      14. 22.1.14. Handling a Button Click
      15. 22.1.15. Responding to the Context Menu
        1. 22.1.15.1. The Logic for Dealing with the Choose Menu Item
        2. 22.1.15.2. Creating the Dialog Form
        3. 22.1.15.3. Developing the Dialog Class
        4. 22.1.15.4. Handling the Click Event for the ChooseMenu
    2. 22.2. Summary
    3. 22.3. Exercises
  28. 23. Accessing Data Sources in a Windows Forms Application
    1. 23.1. Working with Data Sources
    2. 23.2. Accessing and Displaying Data
    3. 23.3. Using a DataGridView Control
    4. 23.4. Using a DataGridView Control in Unbound Mode
    5. 23.5. Customizing a DataGridView Control
      1. 23.5.1. Customizing Header Cells
      2. 23.5.2. Customizing Non-Header Cells
        1. 23.5.2.1. Setting Up the Data
        2. 23.5.2.2. Setting Up the Control
        3. 23.5.2.3. Setting Up the Column Headers
        4. 23.5.2.4. Formatting a Column
        5. 23.5.2.5. Customizing Alternate Rows
      3. 23.5.3. Dynamically Setting Cell Styles
    6. 23.6. Using Bound Mode
    7. 23.7. The BindingSource Component
    8. 23.8. Using the BindingNavigator Control
    9. 23.9. Binding to Individual Controls
    10. 23.10. Working with Multiple Tables
    11. 23.11. Summary
    12. 23.12. Exercises
  29. A. C++ Keywords
    1. A.1. ISO/ANSI C++ Keywords
    2. A.2. C++/CLI Keywords
  30. B. ASCII Codes
  31. C. Windows Message Types

Product information

  • Title: Ivor Horton's Beginning Visual C++®2008
  • Author(s):
  • Release date: March 2008
  • Publisher(s): Wrox
  • ISBN: 9780470225905