You are previewing Ivor Horton's Beginning Visual C++® 2010.
O'Reilly logo
Ivor Horton's Beginning Visual C++® 2010

Book Description

The leading author of programming tutorials for beginners introduces you to Visual C++ 2010

Ivor Horton is the preeminent author of introductory programming language tutorials; previous editions of his Beginning Visual C++ have sold nearly 100,000 copies. This book is a comprehensive introduction to both the Standard C++ language and to Visual C++ 2010; no previous programming experience is required.

All aspects of the 2010 release are covered, including changes to the language and the C++ standard.

Microsoft Visual C++ is one of the most popular C++ development environments and compilers, used by hundreds of thousands of developers

  • Ivor Horton's approach to programming tutorials has achieved a huge following; this book gives beginning programmers a comprehensive introduction to both Standard C++ and Visual C++ 2010

  • Covers all the language changes in Visual C++ 2010, library additions, new MFC features, changes in the Visual Studio development environment, and more

  • Also includes a brief introduction to programming for multicore processors in native C++ and C++/CLR processors

  • Nearly 100,000 copies of this book have been sold in previous editions

  • Beginners seeking a complete education in Visual C++ will find everything they need in Ivor Horton's Beginning Visual C++ 2010.

    Note: CD-ROM/DVD and other supplementary materials are not included as part of eBook file.

    Table of Contents

    1. Copyright
    2. ABOUT THE AUTHOR
    3. ABOUT THE TECHNICAL EDITOR
    4. CREDITS
    5. ACKNOWLEDGMENTS
    6. INTRODUCTION
      1. PROGRAMMING IN C++
      2. DEVELOPING WINDOWS APPLICATIONS
      3. ADVANCED LIBRARY CAPABILITIES
      4. WHO THIS BOOK IS FOR
      5. WHAT THIS BOOK COVERS
      6. HOW THIS BOOK IS STRUCTURED
      7. WHAT YOU NEED TO USE THIS BOOK
      8. CONVENTIONS
      9. SOURCE CODE
      10. ERRATA
      11. P2P.WROX.COM
    7. 1. Programming With Visual C++ 2010
      1. 1.1. THE .NET FRAMEWORK
      2. 1.2. THE COMMON LANGUAGE RUNTIME
      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. The Editor
        2. 1.5.2. The Compiler
        3. 1.5.3. The Linker
        4. 1.5.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
          2. 1.6.4.2. Modifying the Source Code
          3. 1.6.4.3. Building the Solution
          4. 1.6.4.4. Files Created by Building a Console Application
          5. 1.6.4.5. Debug and Release Versions of Your Program
          6. 1.6.4.6. Executing the Program
          7. 1.6.4.7. Dealing with Errors
        5. 1.6.5. Setting Options in Visual C++ 2010
        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
    8. 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/IEC 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
        3. 2.4.3. Formatting the Output
        4. 2.4.4. Escape Sequences
      5. 2.5. CALCULATING IN C++
        1. 2.5.1. The Assignment Statement
        2. 2.5.2. Arithmetic Operations
          1. 2.5.2.1. The const Modifier
          2. 2.5.2.2. Constant Expressions
          3. 2.5.2.3. Program Input
          4. 2.5.2.4. Calculating the Result
          5. 2.5.2.5. 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
        6. 2.5.6. The Sequence of Calculation
          1. 2.5.6.1. Operator Precedence
      6. 2.6. TYPE CONVERSION AND CASTING
        1. 2.6.1. Type Conversion in Assignments
        2. 2.6.2. Explicit Type Conversion
        3. 2.6.3. Old-Style Casts
      7. 2.7. THE AUTO KEYWORD
      8. 2.8. DISCOVERING TYPES
      9. 2.9. THE BITWISE OPERATORS
        1. 2.9.1. The Bitwise AND
        2. 2.9.2. The Bitwise OR
        3. 2.9.3. The Bitwise Exclusive OR
        4. 2.9.4. The Bitwise NOT
        5. 2.9.5. The Bitwise Shift Operators
      10. 2.10. INTRODUCING LVALUES AND RVALUES
      11. 2.11. UNDERSTANDING STORAGE DURATION AND SCOPE
        1. 2.11.1. Automatic Variables
        2. 2.11.2. Positioning Variable Declarations
        3. 2.11.3. Global Variables
        4. 2.11.4. Static Variables
      12. 2.12. NAMESPACES
        1. 2.12.1. Declaring a Namespace
        2. 2.12.2. Multiple Namespaces
      13. 2.13. C++/CLI PROGRAMMING
        1. 2.13.1. C++/CLI Specific: Fundamental Data Types
        2. 2.13.2. C++/CLI Output to the Command Line
        3. 2.13.3. C++/CLI Specific — Formatting the Output
        4. 2.13.4. C++/CLI Input from the Keyboard
        5. 2.13.5. Using safe_cast
        6. 2.13.6. C++/CLI Enumerations
          1. 2.13.6.1. Specifying a Type for Enumeration Constants
          2. 2.13.6.2. Specifying Values for Enumeration Constants
          3. 2.13.6.3. Operations on Enumeration Constants
          4. 2.13.6.4. Using Enumerators as Flags
          5. 2.13.6.5. Native Enumerations in a C++/CLI Program
      14. 2.14. DISCOVERING C++/CLI TYPES
      15. 2.15. SUMMARY
    9. 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. The Extended if Statement
        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
        5. 3.1.5. The Conditional Operator
        6. 3.1.6. The switch Statement
        7. 3.1.7. Unconditional Branching
      2. 3.2. REPEATING A BLOCK OF STATEMENTS
        1. 3.2.1. What Is a Loop?
        2. 3.2.2. Variations on the for Loop
          1. 3.2.2.1. Using the continue Statement
          2. 3.2.2.2. Floating-Point Loop Counters
        3. 3.2.3. The while Loop
        4. 3.2.4. The do-while Loop
        5. 3.2.5. Nested Loops
      3. 3.3. C++/CLI PROGRAMMING
        1. 3.3.1. The for each Loop
      4. 3.4. SUMMARY
    10. 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
        3. 4.1.3. Initializing Arrays
        4. 4.1.4. Character Arrays and String Handling
          1. 4.1.4.1. String Input
        5. 4.1.5. Multidimensional Arrays
          1. 4.1.5.1. Initializing Multidimensional Arrays
      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?
        4. 4.2.4. Initializing Pointers
          1. 4.2.4.1. Pointers to char
        5. 4.2.5. The sizeof Operator
        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. Using Pointers with Multidimensional Arrays
          3. 4.2.7.3. 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
        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 Lvalue References
        3. 4.4.3. Defining and Initializing Rvalue 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
      6. 4.6. C++/CLI PROGRAMMING
        1. 4.6.1. Tracking Handles
          1. 4.6.1.1. Creating Tracking Handles
        2. 4.6.2. CLR Arrays
          1. 4.6.2.1. Sorting One-Dimensional Arrays
          2. 4.6.2.2. Searching One-Dimensional Arrays
          3. 4.6.2.3. Multidimensional Arrays
          4. 4.6.2.4. Arrays of Arrays
        3. 4.6.3. Strings
          1. 4.6.3.1. Joining Strings
          2. 4.6.3.2. Modifying Strings
          3. 4.6.3.3. Comparing Strings
          4. 4.6.3.4. Searching Strings
        4. 4.6.4. Tracking References
        5. 4.6.5. Interior Pointers
      7. 4.7. SUMMARY
    11. 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.2. PASSING ARGUMENTS TO A FUNCTION
        1. 5.2.1. The Pass-by-value Mechanism
        2. 5.2.2. Pointers as Arguments to a Function
        3. 5.2.3. Passing Arrays to a Function
          1. 5.2.3.1. Passing Multidimensional Arrays to a Function
        4. 5.2.4. References as Arguments to a Function
        5. 5.2.5. Use of the const Modifier
        6. 5.2.6. Rvalue Reference Parameters
        7. 5.2.7. Arguments to main()
        8. 5.2.8. Accepting a Variable Number of Function Arguments
      3. 5.3. RETURNING VALUES FROM A FUNCTION
        1. 5.3.1. Returning a Pointer
          1. 5.3.1.1. A Cast-Iron Rule for Returning Addresses
        2. 5.3.2. Returning a Reference
          1. 5.3.2.1. A Teflon-Coated Rule: Returning References
        3. 5.3.3. Static Variables in a Function
      4. 5.4. RECURSIVE FUNCTION CALLS
        1. 5.4.1. Using Recursion
      5. 5.5. C++/CLI PROGRAMMING
        1. 5.5.1. Functions Accepting a Variable Number of Arguments
        2. 5.5.2. Arguments to main()
      6. 5.6. SUMMARY
    12. 6. More about Program Structure
      1. 6.1. POINTERS TO FUNCTIONS
        1. 6.1.1. Declaring Pointers to Functions
        2. 6.1.2. A Pointer to a Function as an Argument
        3. 6.1.3. Arrays of Pointers to Functions
      2. 6.2. INITIALIZING FUNCTION PARAMETERS
      3. 6.3. EXCEPTIONS
        1. 6.3.1. Throwing Exceptions
        2. 6.3.2. Catching Exceptions
        3. 6.3.3. Exception Handling in the MFC
      4. 6.4. HANDLING MEMORY ALLOCATION ERRORS
      5. 6.5. FUNCTION OVERLOADING
        1. 6.5.1. What Is Function Overloading?
        2. 6.5.2. Reference Types and Overload Selection
        3. 6.5.3. When to Overload Functions
      6. 6.6. FUNCTION TEMPLATES
        1. 6.6.1. Using a Function Template
      7. 6.7. USING THE DECLTYPE OPERATOR
      8. 6.8. AN EXAMPLE USING FUNCTIONS
        1. 6.8.1. Implementing a Calculator
          1. 6.8.1.1. Analyzing the Problem
        2. 6.8.2. Eliminating Blanks from a String
          1. 6.8.2.1. How the Function Functions
        3. 6.8.3. Evaluating an Expression
          1. 6.8.3.1. How the Function Functions
        4. 6.8.4. Getting the Value of a Term
          1. 6.8.4.1. How the Function Functions
        5. 6.8.5. Analyzing a Number
          1. 6.8.5.1. How the Function Functions
        6. 6.8.6. Putting the Program Together
          1. 6.8.6.1. How the Function Functions
        7. 6.8.7. Extending the Program
          1. 6.8.7.1. How the Function Functions
        8. 6.8.8. Extracting a Substring
          1. 6.8.8.1. How the Function Functions
        9. 6.8.9. Running the Modified Program
      9. 6.9. C++/CLI PROGRAMMING
        1. 6.9.1. Understanding Generic Functions
          1. 6.9.1.1. Defining Generic Functions
          2. 6.9.1.2. Using Generic Functions
        2. 6.9.2. A Calculator Program for the CLR
          1. 6.9.2.1. Removing Spaces from the Input String
          2. 6.9.2.2. Evaluating an Arithmetic Expression
          3. 6.9.2.3. Obtaining the Value of a Term
          4. 6.9.2.4. Evaluating a Number
          5. 6.9.2.5. Extracting a Parenthesized Substring
      10. 6.10. SUMMARY
    13. 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
        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
        4. 7.3.4. Member Functions of a Class
        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?
        2. 7.4.2. The Default Constructor
        3. 7.4.3. Assigning Default Parameter Values in a Class
        4. 7.4.4. Using an Initialization List in a Constructor
        5. 7.4.5. Making a Constructor Explicit
      5. 7.5. PRIVATE MEMBERS OF A CLASS
        1. 7.5.1. Accessing private Class Members
        2. 7.5.2. The friend Functions of a Class
          1. 7.5.2.1. Placing friend Function Definitions Inside the Class
        3. 7.5.3. The Default Copy Constructor
      6. 7.6. THE POINTER this
      7. 7.7. CONST OBJECTS
        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
      9. 7.9. STATIC MEMBERS OF A CLASS
        1. 7.9.1. Static Data Members
        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 Objects
        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. The ToString() Function in a Class
          2. 7.11.1.2. Literal Fields
        2. 7.11.2. Defining Reference Class Types
        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. Defining Indexed Properties
          4. 7.11.4.4. More Complex Indexed Properties
          5. 7.11.4.5. Static Properties
          6. 7.11.4.6. Reserved Property Names
        5. 7.11.5. initonly Fields
        6. 7.11.6. Static Constructors
      12. 7.12. SUMMARY
    14. 8. More on Classes
      1. 8.1. CLASS DESTRUCTORS
        1. 8.1.1. What Is a Destructor?
        2. 8.1.2. The Default Destructor
        3. 8.1.3. Destructors and Dynamic Memory Allocation
      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
        2. 8.4.2. Implementing Full Support for a Comparison Operator
        3. 8.4.3. Overloading the Assignment Operator
          1. 8.4.3.1. Fixing the Problem
        4. 8.4.4. Overloading the Addition Operator
        5. 8.4.5. Overloading the Increment and Decrement Operators
        6. 8.4.6. Overloading the Function Call Operator
      5. 8.5. THE OBJECT COPYING PROBLEM
        1. 8.5.1. Avoiding Unnecessary Copy Operations
        2. 8.5.2. Applying Rvalue Reference Parameters
        3. 8.5.3. Named Objects are Lvalues
      6. 8.6. CLASS TEMPLATES
        1. 8.6.1. Defining a Class Template
          1. 8.6.1.1. Template Member Functions
        2. 8.6.2. Creating Objects from a Class Template
        3. 8.6.3. Class Templates with Multiple Parameters
        4. 8.6.4. Templates for Function Objects
      7. 8.7. USING CLASSES
        1. 8.7.1. The Idea of a Class Interface
        2. 8.7.2. Defining the Problem
        3. 8.7.3. Implementing the CBox Class
          1. 8.7.3.1. Comparing CBox Objects
          2. 8.7.3.2. Combining CBox Objects
          3. 8.7.3.3. Analyzing CBox Objects
      8. 8.8. ORGANIZING YOUR PROGRAM CODE
        1. 8.8.1. Naming Program Files
      9. 8.9. NATIVE C++ LIBRARY CLASSES FOR STRINGS
        1. 8.9.1. Creating String Objects
        2. 8.9.2. Concatenating Strings
        3. 8.9.3. Accessing and Modifying Strings
        4. 8.9.4. Comparing Strings
        5. 8.9.5. Searching Strings
      10. 8.10. C++/CLI PROGRAMMING
        1. 8.10.1. Overloading Operators in Value Classes
        2. 8.10.2. Overloading the Increment and Decrement Operators
        3. 8.10.3. Overloading Operators in Reference Classes
        4. 8.10.4. Implementing the Assignment Operator for Reference Types
      11. 8.11. SUMMARY
    15. 9. Class Inheritance and Virtual Functions
      1. 9.1. OBJECT-ORIENTED PROGRAMMING BASICS
      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
      3. 9.3. ACCESS CONTROL UNDER INHERITANCE
        1. 9.3.1. Constructor Operation in a Derived Class
        2. 9.3.2. Declaring Protected Class Members
        3. 9.3.3. The Access Level of Inherited Class Members
      4. 9.4. THE COPY CONSTRUCTOR IN A DERIVED CLASS
      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. What Is a Virtual Function?
        2. 9.6.2. Using Pointers to Class Objects
        3. 9.6.3. Using References with Virtual Functions
          1. 9.6.3.1. Incomplete Class Definitions
        4. 9.6.4. Pure Virtual Functions
        5. 9.6.5. Abstract Classes
        6. 9.6.6. Indirect Base Classes
        7. 9.6.7. Virtual Destructors
      7. 9.7. CASTING BETWEEN CLASS TYPES
      8. 9.8. NESTED CLASSES
      9. 9.9. C++/CLI PROGRAMMING
        1. 9.9.1. Boxing and Unboxing
        2. 9.9.2. Inheritance in C++/CLI Classes
        3. 9.9.3. Interface Classes
        4. 9.9.4. Defining Interface Classes
        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. Unbound Delegates
          4. 9.9.7.4. Creating Events
        8. 9.9.8. Destructors and Finalizers in Reference Classes
        9. 9.9.9. Generic Classes
          1. 9.9.9.1. Generic Interface Classes
          2. 9.9.9.2. Generic Collection Classes
          3. 9.9.9.3. List<T> — A Generic List
          4. 9.9.9.4. LinkedList<T> — A Generic Doubly Linked List
          5. 9.9.9.5. Dictionary<TKey, TValue> — A Generic Dictionary Storing Key/Value Pairs
      10. 9.10. SUMMARY
    16. 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 in the STL
        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
        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
        6. 10.3.6. Sorting Vector Elements
        7. 10.3.7. Storing Pointers in a Vector
        8. 10.3.8. Double-Ended Queue Containers
        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. Other Operations on Lists
        10. 10.3.10. Using Other Sequence Containers
          1. 10.3.10.1. Queue Containers
          2. 10.3.10.2. Priority Queue Containers
          3. 10.3.10.3. Stack Containers
          4. 10.3.10.4. The array Container
      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
        2. 10.4.2. Using a Multimap Container
      5. 10.5. MORE ON ITERATORS
        1. 10.5.1. Using Input Stream Iterators
        2. 10.5.2. Using Inserter Iterators
        3. 10.5.3. Using Output Stream Iterators
      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. LAMBDA EXPRESSIONS
        1. 10.8.1. The Capture Clause
        2. 10.8.2. Capturing Specific Variables
        3. 10.8.3. Templates and Lambda Expressions
        4. 10.8.4. Wrapping a Lambda Expression
      9. 10.9. THE STL FOR C++/CLI PROGRAMS
        1. 10.9.1. STL/CLR Containers
        2. 10.9.2. Using Sequence Containers
        3. 10.9.3. Using Associative Containers
      10. 10.10. LAMBDA EXPRESSIONS IN C++/CLI
      11. 10.11. SUMMARY
    17. 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
      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 for Checking the Free Store
        2. 11.6.2. Controlling Free Store Debug Operations
        3. 11.6.3. Free Store Debugging Output
      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
        2. 11.7.2. Getting Trace Output in Windows Forms Applications
      8. 11.8. SUMMARY
    18. 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
      5. 12.5. USING WINDOWS FORMS
      6. 12.6. SUMMARY
    19. 13. Programming for Multiple Cores
      1. 13.1. PARALLEL PROCESSING BASICS
      2. 13.2. INTRODUCING THE PARALLEL PATTERNS LIBRARY
      3. 13.3. ALGORITHMS FOR PARALLEL PROCESSING
        1. 13.3.1. Using the parallel_for Algorithm
        2. 13.3.2. Using the parallel_for_each Algorithm
        3. 13.3.3. Using the parallel_invoke Algorithm
      4. 13.4. A REAL PARALLEL PROBLEM
      5. 13.5. CRITICAL SECTIONS
        1. 13.5.1. Using critical_section Objects
        2. 13.5.2. Locking and Unlocking a Section of Code
      6. 13.6. THE COMBINABLE CLASS TEMPLATE
      7. 13.7. TASKS AND TASK GROUPS
      8. 13.8. SUMMARY
    20. 14. Windows Programming with the Microsoft Foundation Classes
      1. 14.1. THE DOCUMENT/VIEW CONCEPT IN MFC
        1. 14.1.1. What Is a Document?
        2. 14.1.2. Document Interfaces
        3. 14.1.3. What Is a View?
        4. 14.1.4. Linking a Document and Its Views
          1. 14.1.4.1. Document Templates
          2. 14.1.4.2. Document Template Classes
        5. 14.1.5. Your Application and MFC
      2. 14.2. CREATING MFC APPLICATIONS
        1. 14.2.1. Creating an SDI Application
        2. 14.2.2. MFC Application Wizard Output
          1. 14.2.2.1. Viewing Project Files
          2. 14.2.2.2. Viewing Classes
          3. 14.2.2.3. The Class Definitions
          4. 14.2.2.4. Creating an Executable Module
            1. 14.2.2.4.1. Precompiled Header Files
          5. 14.2.2.5. Running the Program
          6. 14.2.2.6. How the Program Works
            1. 14.2.2.6.1. The InitInstance() Function
            2. 14.2.2.6.2. The Run() Function
        3. 14.2.3. Creating an MDI Application
          1. 14.2.3.1. Running the Program
      3. 14.3. SUMMARY
    21. 15. Working with Menus and Toolbars
      1. 15.1. COMMUNICATING WITH WINDOWS
        1. 15.1.1. Understanding Message Maps
          1. 15.1.1.1. Message Handler Definitions
        2. 15.1.2. Message Categories
        3. 15.1.3. Handling Messages in Your Program
          1. 15.1.3.1. How Command Messages Are Processed
      2. 15.2. EXTENDING THE SKETCHER PROGRAM
      3. 15.3. ELEMENTS OF A MENU
        1. 15.3.1. Creating and Editing Menu Resources
          1. 15.3.1.1. Adding a Menu Item to the Menu Bar
          2. 15.3.1.2. Adding Items to the Element Menu
          3. 15.3.1.3. Modifying Existing Menu Items
          4. 15.3.1.4. Completing the Menu
      4. 15.4. ADDING HANDLERS FOR MENU MESSAGES
        1. 15.4.1. Choosing a Class to Handle Menu Messages
        2. 15.4.2. Creating Menu Message Functions
        3. 15.4.3. Coding Menu Message Functions
          1. 15.4.3.1. Adding Members to Store Color and Element Mode
          2. 15.4.3.2. Initializing the New Class Data Members
            1. 15.4.3.2.1. Modifying the Class Constructor
          3. 15.4.3.3. Running the Extended Example
        4. 15.4.4. Adding Message Handlers to Update the User Interface
          1. 15.4.4.1. Coding a Command Update Handler
          2. 15.4.4.2. Exercising the Update Handlers
      5. 15.5. ADDING TOOLBAR BUTTONS
        1. 15.5.1. Editing Toolbar Button Properties
        2. 15.5.2. Exercising the Toolbar Buttons
        3. 15.5.3. Adding Tooltips
      6. 15.6. MENUS AND TOOLBARS IN A C++/CLI PROGRAM
        1. 15.6.1. Understanding Windows Forms
        2. 15.6.2. Understanding Windows Forms Applications
          1. 15.6.2.1. Modifying the Properties of a Form
          2. 15.6.2.2. How the Application Starts
        3. 15.6.3. Adding a Menu to CLR Sketcher
        4. 15.6.4. Adding Event Handlers for Menu Items
        5. 15.6.5. Implementing Event Handlers
        6. 15.6.6. Setting Menu Item Checks
        7. 15.6.7. Adding a Toolbar
      7. 15.7. SUMMARY
    22. 16. Drawing in a Window
      1. 16.1. BASICS OF DRAWING IN A WINDOW
        1. 16.1.1. The Window Client Area
        2. 16.1.2. The Windows Graphical Device Interface
          1. 16.1.2.1. Working with a Device Context
          2. 16.1.2.2. Mapping Modes
      2. 16.2. THE DRAWING MECHANISM IN VISUAL C++
        1. 16.2.1. The View Class in Your Application
          1. 16.2.1.1. The OnDraw() Member Function
        2. 16.2.2. The CDC Class
          1. 16.2.2.1. Displaying Graphics
            1. 16.2.2.1.1. Drawing Lines
            2. 16.2.2.1.2. Drawing Circles
          2. 16.2.2.2. Drawing in Color
            1. 16.2.2.2.1. Creating a Pen
            2. 16.2.2.2.2. Using a Pen
            3. 16.2.2.2.3. Creating a Brush
            4. 16.2.2.2.4. Using a Brush
      3. 16.3. DRAWING GRAPHICS IN PRACTICE
      4. 16.4. PROGRAMMING FOR THE MOUSE
        1. 16.4.1. Messages from the Mouse
          1. 16.4.1.1. WM_LBUTTONDOWN
          2. 16.4.1.2. WM_MOUSEMOVE
          3. 16.4.1.3. WM_LBUTTONUP
        2. 16.4.2. Mouse Message Handlers
        3. 16.4.3. Drawing Using the Mouse
          1. 16.4.3.1. Getting the Client Area Redrawn
          2. 16.4.3.2. Defining Classes for Elements
            1. 16.4.3.2.1. Storing a Temporary Element in the View
          3. 16.4.3.3. The CElement Class
          4. 16.4.3.4. The CLine Class
            1. 16.4.3.4.1. Implementing the CLine Class
            2. 16.4.3.4.2. The CLine Class Constructor
            3. 16.4.3.4.3. Drawing a Line
            4. 16.4.3.4.4. Creating Bounding Rectangles
            5. 16.4.3.4.5. Normalized Rectangles
          5. 16.4.3.5. Calculating the Enclosing Rectangle for a Line
          6. 16.4.3.6. The CRectangle Class
          7. 16.4.3.7. The CRectangle Class Constructor
            1. 16.4.3.7.1. Drawing a Rectangle
          8. 16.4.3.8. The CCircle Class
            1. 16.4.3.8.1. Implementing the CCircle Class
            2. 16.4.3.8.2. The CCircle Class Constructor
            3. 16.4.3.8.3. Drawing a Circle
          9. 16.4.3.9. The CCurve Class
            1. 16.4.3.9.1. Drawing a Curve
          10. 16.4.3.10. Completing the Mouse Message Handlers
            1. 16.4.3.10.1. Setting the Drawing Mode
            2. 16.4.3.10.2. Coding the OnMouseMove() Handler
            3. 16.4.3.10.3. Creating an Element
            4. 16.4.3.10.4. Dealing with WM_LBUTTONUP Messages
      5. 16.5. EXERCISING SKETCHER
        1. 16.5.1. Running the Example
        2. 16.5.2. Capturing Mouse Messages
      6. 16.6. DRAWING WITH THE CLR
        1. 16.6.1. Drawing on a Form
        2. 16.6.2. Adding Mouse Event Handlers
        3. 16.6.3. Defining C++/CLI Element Classes
          1. 16.6.3.1. Defining a Line
            1. 16.6.3.1.1. Defining a Color
            2. 16.6.3.1.2. Drawing Lines
            3. 16.6.3.1.3. Defining a Pen for Drawing
            4. 16.6.3.1.4. Standard Pens
          2. 16.6.3.2. Defining a Rectangle
          3. 16.6.3.3. Defining a Circle
          4. 16.6.3.4. Defining a Curve
        4. 16.6.4. Implementing the MouseMove Event Handler
        5. 16.6.5. Implementing the MouseUp Event Handler
        6. 16.6.6. Implementing the Paint Event Handler for the Form
      7. 16.7. SUMMARY
    23. 17. Creating the Document and Improving the View
      1. 17.1. CREATING THE SKETCH DOCUMENT
        1. 17.1.1. Using a list<T> Container for the Sketch
          1. 17.1.1.1. Implementing the Document Destructor
          2. 17.1.1.2. Drawing the Document
          3. 17.1.1.3. Adding an Element to the Document
          4. 17.1.1.4. Exercising the Document
      2. 17.2. IMPROVING THE VIEW
        1. 17.2.1. Updating Multiple Views
        2. 17.2.2. Scrolling Views
          1. 17.2.2.1. Logical Coordinates and Client Coordinates
          2. 17.2.2.2. Dealing with Client Coordinates
        3. 17.2.3. Using MM_LOENGLISH Mapping Mode
      3. 17.3. DELETING AND MOVING SHAPES
      4. 17.4. IMPLEMENTING A CONTEXT MENU
        1. 17.4.1. Associating a Menu with a Class
          1. 17.4.1.1. Identifying a Selected Element
        2. 17.4.2. Exercising the Pop-Ups
        3. 17.4.3. Highlighting Elements
          1. 17.4.3.1. Drawing Highlighted Elements
          2. 17.4.3.2. Exercising the Highlights
        4. 17.4.4. Servicing the Menu Messages
          1. 17.4.4.1. Deleting an Element
          2. 17.4.4.2. Moving an Element
          3. 17.4.4.3. Modifying the WM_MOUSEMOVE Handler
          4. 17.4.4.4. Getting the Elements to Move Themselves
          5. 17.4.4.5. Dropping the Element
          6. 17.4.4.6. Exercising the Application
      5. 17.5. DEALING WITH MASKED ELEMENTS
      6. 17.6. EXTENDING CLR SKETCHER
        1. 17.6.1. Coordinate System Transformations
        2. 17.6.2. Defining a Sketch Class
        3. 17.6.3. Drawing the Sketch in the Paint Event Handler
        4. 17.6.4. Implementing Element Highlighting
          1. 17.6.4.1. Finding the Element to Highlight
          2. 17.6.4.2. Highlighting the Element
        5. 17.6.5. Adjusting the Bounding Rectangle for an Element
        6. 17.6.6. Creating Context Menus
          1. 17.6.6.1. Implementing the Element Delete Operation
          2. 17.6.6.2. Implementing the "Send to Back" Operation
          3. 17.6.6.3. Implementing the Element Move Operation
          4. 17.6.6.4. Moving an Element
      7. 17.7. SUMMARY
    24. 18. Working with Dialogs and Controls
      1. 18.1. UNDERSTANDING DIALOGS
      2. 18.2. UNDERSTANDING CONTROLS
      3. 18.3. CREATING A DIALOG RESOURCE
        1. 18.3.1. Adding Controls to a Dialog Box
        2. 18.3.2. Testing the Dialog
      4. 18.4. PROGRAMMING FOR A DIALOG
        1. 18.4.1. Adding a Dialog Class
        2. 18.4.2. Modal and Modeless Dialogs
        3. 18.4.3. Displaying a Dialog
          1. 18.4.3.1. Code to Display the Dialog
          2. 18.4.3.2. Code to Close the Dialog
      5. 18.5. SUPPORTING THE DIALOG CONTROLS
        1. 18.5.1. Initializing the Controls
        2. 18.5.2. Handling Radio Button Messages
      6. 18.6. COMPLETING DIALOG OPERATIONS
        1. 18.6.1. Adding Pen Widths to the Document
        2. 18.6.2. Adding Pen Widths to the Elements
        3. 18.6.3. Creating Elements in the View
        4. 18.6.4. Exercising the Dialog
      7. 18.7. USING A SPIN BUTTON CONTROL
        1. 18.7.1. Adding the Scale Menu Item and Toolbar Button
        2. 18.7.2. Creating the Spin Button
          1. 18.7.2.1. The Controls' Tab Sequence
        3. 18.7.3. Generating the Scale Dialog Class
          1. 18.7.3.1. Dialog Data Exchange and Validation
          2. 18.7.3.2. Initializing the Dialog
        4. 18.7.4. Displaying the Spin Button
      8. 18.8. USING THE SCALE FACTOR
        1. 18.8.1. Scalable Mapping Modes
        2. 18.8.2. Setting the Document Size
        3. 18.8.3. Setting the Mapping Mode
        4. 18.8.4. Implementing Scrolling with Scaling
          1. 18.8.4.1. Setting Up the Scrollbars
      9. 18.9. USING THE CTASKDIALOG CLASS
        1. 18.9.1. Displaying a Task Dialog
        2. 18.9.2. Creating CTaskDialog Objects
          1. 18.9.2.1. Adding Radio Buttons
          2. 18.9.2.2. Getting Output from Radio Buttons
      10. 18.10. WORKING WITH STATUS BARS
        1. 18.10.1. Adding a Status Bar to a Frame
          1. 18.10.1.1. Creating Status Bar Panes
          2. 18.10.1.2. Updating the Status Bar
      11. 18.11. USING A LIST BOX
        1. 18.11.1. Removing the Scale Dialog
        2. 18.11.2. Creating a List Box Control
          1. 18.11.2.1. Creating the Dialog Class
          2. 18.11.2.2. Displaying the Dialog
      12. 18.12. USING AN EDIT BOX CONTROL
        1. 18.12.1. Creating an Edit Box Resource
        2. 18.12.2. Creating the Dialog Class
          1. 18.12.2.1. The CString Class
        3. 18.12.3. Adding the Text Menu Item
        4. 18.12.4. Defining a Text Element
        5. 18.12.5. Implementing the CText Class
          1. 18.12.5.1. The CText Constructor
          2. 18.12.5.2. Creating a Text Element
          3. 18.12.5.3. Drawing a CText Object
          4. 18.12.5.4. Moving a CText Object
      13. 18.13. DIALOGS AND CONTROLS IN CLR SKETCHER
        1. 18.13.1. Adding a Dialog
          1. 18.13.1.1. Customizing the Dialog
          2. 18.13.1.2. Displaying the Dialog
          3. 18.13.1.3. Creating Elements with a Pen Width
          4. 18.13.1.4. Using a Combo Box Control
        2. 18.13.2. Creating Text Elements
          1. 18.13.2.1. Drawing Text
          2. 18.13.2.2. Creating Fonts
          3. 18.13.2.3. Creating Brushes
          4. 18.13.2.4. Choosing a Font
          5. 18.13.2.5. Defining the Text Element Class
          6. 18.13.2.6. Creating the Text Dialog
            1. 18.13.2.6.1. Using a Text Box
            2. 18.13.2.6.2. Displaying the Dialog and Creating a Text Element
      14. 18.14. SUMMARY
    25. 19. Storing and Printing Documents
      1. 19.1. UNDERSTANDING SERIALIZATION
      2. 19.2. SERIALIZING A DOCUMENT
        1. 19.2.1. Serialization in the Document Class Definition
        2. 19.2.2. Serialization in the Document Class Implementation
          1. 19.2.2.1. The Serialize() Function
          2. 19.2.2.2. The CArchive Class
        3. 19.2.3. Functionality of CObject-Based Classes
          1. 19.2.3.1. The Macros Adding Serialization to a Class
        4. 19.2.4. How Serialization Works
        5. 19.2.5. How to Implement Serialization for a Class
      3. 19.3. APPLYING SERIALIZATION
        1. 19.3.1. Recording Document Changes
        2. 19.3.2. Serializing the Document
        3. 19.3.3. Serializing the Element Classes
          1. 19.3.3.1. The Serialize() Functions for the Shape Classes
      4. 19.4. EXERCISING SERIALIZATION
      5. 19.5. PRINTING A DOCUMENT
        1. 19.5.1. The Printing Process
          1. 19.5.1.1. The CPrintInfo Class
      6. 19.6. IMPLEMENTING MULTIPAGE PRINTING
        1. 19.6.1. Getting the Overall Document Size
        2. 19.6.2. Storing Print Data
        3. 19.6.3. Preparing to Print
        4. 19.6.4. Cleaning Up after Printing
        5. 19.6.5. Preparing the Device Context
        6. 19.6.6. Printing the Document
        7. 19.6.7. Getting a Printout of the Document
      7. 19.7. SERIALIZATION AND PRINTING IN CLR SKETCHER
        1. 19.7.1. Understanding Binary Serialization
          1. 19.7.1.1. Dealing with Fields That Are Not Serializable
          2. 19.7.1.2. Serializing an Object
        2. 19.7.2. Serializing a Sketch
          1. 19.7.2.1. Making the Sketch Class Serializable
          2. 19.7.2.2. Dealing with Pen and Brush Objects
          3. 19.7.2.3. Making the Curve Class Serializable
          4. 19.7.2.4. Implementing File Operations for a Sketch
            1. 19.7.2.4.1. Creating Dialogs for File Operations
            2. 19.7.2.4.2. Recording the Saved State of a Sketch
            3. 19.7.2.4.3. Saving a Sketch
            4. 19.7.2.4.4. Retrieving a Sketch from a File
            5. 19.7.2.4.5. Implementing the File New Operation
            6. 19.7.2.4.6. Dealing with Closing the Form
            7. 19.7.2.4.7. Supporting the Toolbar Buttons
        3. 19.7.3. Printing a Sketch
          1. 19.7.3.1. Using the PrintDocument Component
          2. 19.7.3.2. Implementing the Print Operation
      8. 19.8. SUMMARY
    26. 20. Writing Your Own DLLs
      1. 20.1. UNDERSTANDING DLLS
        1. 20.1.1. How DLLs Work
          1. 20.1.1.1. Runtime Dynamic Linking
        2. 20.1.2. Contents of a DLL
          1. 20.1.2.1. The DLL Interface
          2. 20.1.2.2. The DllMain() Function
        3. 20.1.3. DLL Varieties
          1. 20.1.3.1. MFC Extension DLL
          2. 20.1.3.2. Regular DLL — Statically Linked to MFC
          3. 20.1.3.3. Regular DLL — Dynamically Linked to MFC
      2. 20.2. DECIDING WHAT TO PUT IN A DLL
      3. 20.3. WRITING DLLS
        1. 20.3.1. Writing and Using an Extension DLL
          1. 20.3.1.1. Understanding DllMain()
          2. 20.3.1.2. Adding Classes to the Extension DLL
          3. 20.3.1.3. Exporting Classes from the Extension DLL
          4. 20.3.1.4. Building a DLL
          5. 20.3.1.5. Importing Classes from a DLL
          6. 20.3.1.6. Using the Extension DLL in Sketcher
          7. 20.3.1.7. Files Required to Use a DLL
      4. 20.4. SUMMARY