Introduction
What's New in the Second Edition
What's On the CD
From Me to You (and You to Me)
PART Ⅰ: Fundamental of Windows and MFC
Chapter 1. Hello, MFC
1.1. The Windows Programming Model
1.1.1. Messages, Messages, and More Messages
1.1.2. Windows Programming, SDK-Style
1.1.3. Hungarian Notation and Windows Data Types
1.1.4. SDK Programming in Perspective
1.2. Introducing MFC
1.2.1. The Benefits of Using C++ and MFC
1.2.2. The MFC Design Philosophy
1.2.3. The Document/View Architecture
1.2.4. The MFC Class Hierarchy
1.2.5. AFX Functions
1.3. Your First MFC Application
1.3.1. The Application Object
1.3.2. How MFC Uses the Application Object
1.3.3. The Frame Window Object
1.3.4. Painting the Window
1.3.5. The Message Map
1.3.6. How Message Maps Work
1.3.7. Windows, Character Sets, and the _T Macro
1.3.8. Building the Application
1.3.9. The Big Picture
Chapter 2. Drawing in a Window
2.1. The Windows GDI
2.1.2. The MFC Device Context Classes
2.1.3. Device Context Attributes
2.1.4. The Drawing Mode
2.1.5. The Mapping Mode
2.2. Drawing with the GDI
2.2.1. Drawing Lines and Curves
2.2.2. Drawing Ellipses, Polygons, and Other Shapes
2.2.3. GDI Pens and the CPen Class
2.2.4. GDI Brushes and the CBrush Class
2.2.5. Drawing Text
2.2.6. GDI Fonts and the CFont Class
2.2.7. Raster Fonts vs. TrueType Fonts
2.2.8. Rotated Text
2.2.9. Stock Objects
2.2.10. Deleting GDI Objects
2.2.11. Deselecting GDI Objects
2.2.12. The Ruler Application
2.3. Seeing What You've Drawn
2.3.1. Adding a Scroll Bar to a Window
2.3.2. Setting a Scroll Bar's Range, Position, and Page Size
2.3.3. Synchronizing the Thumb Size and the Window Size
2.3.4. Processing Scroll Bar Messages
2.3.5. Scrolling a Window
2.3.6. The Accel Application
2.4. Loose Ends
Chapter 3. The Mouse and the Keyboard
3.1. Getting Input from the Mouse
3.1.1. More About the TicTac Window
3.1.2. The PostNcDestroy Function
3.1.3. Nonclient-Area Mouse Messages
3.1.4. The WM_NCHITTEST Message
3.1.5. The WM_MOUSELEAVE and WM_MOUSEHOVER Messages
3.2. Getting Input from the Keyboard
3.2.1. The Input Focus
3.2.2. Keystroke Messages
3.2.3. Virtual Key Codes
3.2.4. Shift States and Toggles
3.2.5. Character Messages
3.2.6. Dead-Key Messages
3.2.7. The Caret
3.3. The VisualKB Application
3.3.1. Handling the Caret
3.3.2. Entering and Editing Text
3.3.3. Other Points of Interest
Chapter 4. Menus
4.1. Menu Basics
4.1.1. Creating a Menu
4.1.2. Loading and Displaying a Menu
4.1.3. Responding to Menu Commands
4.1.4. Command Ranges
4.1.5. Updating the Items in a Menu
4.1.6. Update Ranges
4.1.7. Keyboard Accelerators
4.2. The Shapes Application
4.2.1. Running the MFC AppWizard
4.2.2. Analyzing AppWizard's Output
4.2.3. Beyond AppWizard
4.2.4. The Process in Review
4.3. Menu Magic
4.3.1. Creating Menus Programmatically
4.3.2. Modifying Menus Programmatically
4.3.3. The System Menu
4.3.4. Owner-Draw Menus
4.3.5. OnMenuChar Processing
4.3.6. Cascading Menus
4.3.7. Context Menus
4.3.8. The TPM_RETURNCMD Flag
4.4. The Colors Application
4.4.1. The Context Menu
4.4.2. On Your Own
Chapter 5. The MFC Collection Classes
5.1. Arrays
5.1.1. The MFC Array Classes
5.1.2. Dynamic Array Sizing
5.1.3. Creating Type-Safe Array Classes with CArray
5.2. Lists
5.2.1. The MFC List Classes
5.2.2. Creating Type-Safe List Classes with CList
5.3. Maps
5.3.1. The MFC Map Classes
5.3.2. How Maps Work
5.3.3. Optimizing Lookup Efficiency
5.3.4. Creating Type-Safe Map Classes with CMap
5.4. The Typed Pointer Classes
Chapter 6. File I/O and Serialization
6.1. The CFile Class
6.1.1. Opening, Closing, and Creating Files
6.1.2. Reading and Writing
6.1.3. CFile Derivatives
6.1.4. Enumerating Files and Folders
6.2. Serialization and the CArchive Class
6.2.1. Serialization Basics
6.2.2. Writing Serializable Classes
6.2.3. Versioning Serializable Classes: Versionable Schemas
6.2.4. How Serialization Works
6.2.5. Serializing CObjects
Chapter 7. Controls
7.1. The Classic Controls
7.1.1. The CButton Class
7.1.1.1. Push Buttons
7.1.1.2. Check Boxes
7.1.1.3. Radio Buttons
7.1.1.4. Group Boxes
7.1.2. The CListBox Class
7.1.2.1. Creating a List Box
7.1.2.2. Adding and Removing Items
7.1.2.3. Finding and Retrieving Items
7.1.2.4. List Box Notifications
7.1.3. The CStatic Class
7.1.4. The FontView Application
7.1.4.1. Font Enumerations and Callback Functions
7.1.5. The CEdit Class
7.1.5.1. Creating an Edit Control
7.1.5.2. Inserting and Retrieving Text
7.1.5.3. Clear, Cut, Copy, Paste, and Undo
7.1.5.4. Edit Control Notifications
7.1.5.5. Presto! Instant Notepad
7.1.6. The CComboBox Class
7.1.6.1. Combo Box Notifications
7.1.7. The CScrollBar Class
7.2. Advanced Control Programming
7.2.1. Numeric Edit Controls
7.2.2. Owner-Draw List Boxes
7.2.3. Graphical Push Buttons
7.2.4. Customizing a Control's Colors
7.2.5. Message Reflection
Chapter 8. Dialog Boxes and Property Sheets
8.1. Modal Dialog Boxes and the CDialog Class
8.1.1. The Dialog Box Template
8.1.2. The CDialog Class
8.1.3. Creating a Modal Dialog Box
8.1.4. Dialog Data Exchange and Dialog Data Validation
8.1.5. Interacting with the Controls in a Dialog
8.1.6. The DlgDemo1 Application
8.2. Modeless Dialog Boxes
8.2.1. The DlgDemo2 Application
8.2.1.1. Processing the Apply and Close Buttons
8.3. Using a Dialog Box as a Main Window
8.3.1. Processing Keyboard Messages
8.3.2. Preprocessing WM_COMMAND Messages
8.4. Property Sheets
8.4.1. The PropDemo Application
8.5. The Common Dialogs
8.5.1. Modifying the Common Dialogs
8.5.2. The Phones Application
PART Ⅱ: The Documents/View Architecture
Chapter 9. Documents, Views, and the Single Document Interface
9.1. Document/View Fundamentals
9.1.1. The InitInstance Function Revisited
9.1.2. The Document Object
9.1.2.1. CDocument Operations
9.1.2.2. CDocument Overridables
9.1.3. The View Object
9.1.3.1. The GetDocument Function
9.1.3.2. CView Overridables
9.1.4. The Frame Window Object
9.1.5. Dynamic Object Creation
9.1.6. More on the SDI Document Template
9.1.7. Registering Document Types with the Operating System Shell
9.1.8. Command Routing
9.1.9. Predefined Command IDs and Command Handlers
9.2. Your First Document/View Application
9.2.1. The SdiSquares Application
9.2.2. SdiSquares Step by Step
9.3. Doc + View = Less Work for You
Chapter 10. Scroll Views, HTML Views, and Other View Types
10.1. Scroll Views
10.1.1. CScrollView Basics
10.1.2. CScrollView Operations
10.1.3. Optimizing Scrolling Performance
10.1.4. The ScrollDemo Application
10.1.5. Converting an Ordinary View into a Scroll View
10.2. HTML Views
10.2.1. CHtmlView Operations
10.2.2. CHtmlView Overridables
10.2.3. Utilizing DHTML in CHtmlView-Based Applications
10.3. Tree Views
10.3.1. Initializing a Tree View
10.3.2. Tree View Member Functions and Notifications
10.3.3. The DriveTree Application
10.3.3.1. Removing the Document Name from the Title Bar
10.4. List Views
10.4.1. Initializing a List View
10.4.2. Changing the Presentation Style
10.4.3. Sorting in a List View
10.4.4. Hit-Testing in a List View
10.4.5. The WinDir Application
10.5. Do-It-Yourself Control Views
Chapter 11. Multiple Documents and Multiple Views
11.1. MFC and the Multiple Document Interface
11.1.1. Synchronizing Multiple Views of a Document
11.1.2. The MdiSquares Application
11.1.3. Supporting Multiple Document Types
11.1.4. Alternatives to MDI
11.2. Splitter Windows
11.2.1. Dynamic Splitter Windows
11.2.2. The Sketch Application
11.2.3. Static Splitter Windows
11.2.4. The Wanderer Application
11.2.5. Custom Command Routing
11.2.6. Three-Way Splitter Windows
11.2.7. Dynamic Splitter Windows with Multiple View Types
Chapter 12. Toolbars, Status Bars, and Rebars
12.1. Toolbars
12.1.1. Creating and Initializing a Toolbar
12.1.2. Docking and Floating
12.1.3. Controlling a Toolbar's Visibility
12.1.4. Keeping Toolbar Buttons in Sync with Your Application
12.1.5. Adding ToolTips and Flyby Text
12.1.6. Adding Non-Push-Button Controls to a Toolbar
12.1.7. Updating Non-Push-Button Controls
12.1.8. Making Toolbar Settings Persistent
12.1.9. Toolbar Support in AppWizard
12.2. Status Bars
12.2.1. Creating and Initializing a Status Bar
12.2.2. Providing Context-Sensitive Help for Menu Items
12.2.3. Creating Custom Status Bar Panes
12.2.4. Status Bar Support in AppWizard
12.3. Putting It All Together: The MyWord Application
12.3.1. The Main Toolbar
12.3.2. The Style Bar
12.3.3. More About CRichEditView
12.4. Rebars
Chapter 13. Printing and Print Previewing
13.1. Printing with Documents and Views
13.1.1. The Windows Print Architecture
13.1.1.1. The Abort Procedure and the Abort Dialog
13.1.1.2. Print Spooling
13.1.2. The MFC Print Architecture
13.1.2.1. More on the OnPreparePrinting Function
13.1.2.2. The OnBeginPrinting andOnEndPrinting Functions
13.1.2.3. The OnPrepareDC Function
13.1.2.4. The OnPrint Function
13.1.2.5. CView::OnFilePrint and Other Command Handlers
13.1.3. Print Previewing
13.2. A Bare-Bones Printing Application
13.2.1. Black-and-White Print Previews
13.3. A More Complex Printing Application
13.3.1. A Unique Approach to Serialization
13.4. Printing Tips and Tricks
13.4.1. Using the Print Dialog's Selection Button
13.4.2. Assume Nothing—And Test Thoroughly!
13.4.3. Adding Default Pagination Support
13.4.4. Enumerating Printers
PART Ⅲ: Beyong the Basics
Chapter 14. Timers and Idle Processing
14.1. Timer
14.1.1. Setting a Timer: Method 1
14.1.2. Responding to WM_TIMER Messages
14.1.3. Setting a Timer: Method 2
14.1.4. Stopping a Timer
14.2. The Clock Application
14.2.1. Processing Timer Messages
14.2.2. Getting the Current Time:The CTime Class
14.2.3. Using the MM_ISOTROPIC Mapping Mode
14.2.4. Hiding and Displaying the Title Bar
14.2.5. Implementing Client-Area Drag
14.2.6. Using the System Menu as a Context Menu
14.2.7. Topmost Windows
14.2.8. Making Configuration Settings Persistent
14.2.9. Controlling the Window Size: The WM_GETMINMAXINFO Message
14.3. Idle Processing
14.3.1. Using OnIdle
14.3.2. Idle Processing vs. Multithreading
Chapter 15. Bitmaps, Palettes, and Regions
15.1. Palettes
15.1.1. How Windows Uses Color
15.1.2. Logical Palettes and the CPalette Class
15.1.3. Creating a Logical Palette
15.1.4. Realizing a Logical Palette
15.1.5. Drawing with Palette Colors
15.1.6. The WM_QUERYNEWPALETTE and WM_PALETTECHANGED Msg
15.1.6.1. Handling Palette Messages in Document/View Applications
15.1.7. Determining Whether a Logical Palette Is Needed
15.1.8. The PaletteDemo Application
15.1.9. Palette Animation
15.1.10. The ::SetSystemPaletteUse Function
15.2. Bitmaps
15.2.1. DDBs and the CBitmap Class
15.2.2. Blitting Bitmaps to Screens and Other Devices
15.2.3. Bitmap Resources
15.2.4. DIBs and DIB Sections
15.2.5. Blits, Raster Operations, and Color Mapping
15.2.6. The BitmapDemo Application
15.2.7. Writing a BMP File Viewer
15.2.8. More on the ::LoadImage Function
15.3. Regions
15.3.1. Regions and the CRgn Class
15.3.1.1. Creating Regions
15.3.1.2. Using Regions
15.3.2. The RegionDemo Application
Chapter 16. The Common Controls
16.1. Common Control Fundamentals
16.1.1. Creating a Common Control
16.1.2. Processing Notifications: The WM_NOTIFY Message
16.2. Slider, Spin Button, and ToolTip Controls
16.2.1. Slider Controls
16.2.2. Spin Button Controls
16.2.3. ToolTip Controls
16.2.3.1. Dynamic ToolTips
16.2.4. The GridDemo Application
16.3. Image Lists and ComboBoxEx Controls
16.3.1. Image Lists
16.3.2. ComboBoxEx Controls
16.3.3. The PathList Application
16.4. Progress Controls and Animation Controls
16.4.1. Progress Controls
16.4.2. Animation Controls
16.5. IP Address Controls and Other Data-Entry Controls
16.5.1. IP Address Controls
16.5.2. Hotkey Controls
16.5.3. Month Calendar Controls
16.5.4. Date-Time Picker Controls
Chapter 17. Threads and Thread Synchronization
17.1. Threads
17.1.1. Creating a Worker Thread
17.1.1.1. The Thread Function
17.1.2. Creating a UI Thread
17.1.3. Suspending and Resuming Threads
17.1.4. Putting Threads to Sleep
17.1.5. Terminating a Thread
17.1.6. Autodeleting CWinThreads
17.1.7. Terminating Another Thread
17.1.8. Threads, Processes, and Priorities
17.1.8.1. Process Priority Classes
17.1.8.2. Relative Thread Priorities
17.1.9. Using C Run-Time Functions in Multithreaded Applications
17.1.10. Calling MFC Member Functions Across Thread Boundaries
17.1.11. Your First Multithreaded Application
17.2. Thread Synchronization
17.2.1. Critical Sections
17.2.2. Mutexes
17.2.3. Events
17.2.4. Semaphores
17.2.5. The CSingleLock and CMultiLock Classes
17.2.6. Writing Thread-Safe Classes
17.2.7. The ImageEdit Application
17.3. Odds and Ends
17.3.1. Message Pumps
17.3.2. Launching Other Processes
17.3.3. File Change Notifications
PART Ⅳ: COM, OLE and ActiveX
Chapter 18. MFC and the Component Object Model
18.1. The Component Object Model
18.1.1. Instantiating a COM Object
18.1.2. Object Lifetimes
18.1.3. Acquiring Interface Pointers
18.1.4. COM Servers
18.1.5. Location Transparency
18.1.6. Object Linking and Embedding
18.1.7. Active Documents
18.1.8. ActiveX
18.2. MFC and COM
18.2.1. Multiple Inheritance
18.2.2. Nested Classes
18.2.3. MFC and Nested Classes
18.2.4. How MFC Implements IUnknown
18.2.5. Interface Maps
18.2.6. MFC and Aggregation
18.2.7. MFC and Class Factories
18.2.8. Putting It All in Perspective
Chapter 19. The Clipboard and OLE Drag-and-Drop
19.1. The Legacy Clipboard
19.1.1. Clipboard Formats
19.1.1.1. The CF_HDROP Clipboard Format
19.1.2. Private Clipboard Formats
19.1.3. Providing Data in Multiple Formats
19.1.4. Querying for Available Data Formats
19.1.5. Delayed Rendering
19.1.6. Building a Reusable Clipboard Class
19.2. The OLE Clipboard
19.2.1. OLE Clipboard Basics
19.2.2. MFC, Global Memory, and the OLE Clipboard
19.2.3. Using Alternative Storage Media
19.2.4. Treating the OLE Clipboard as a CFile
19.2.5. Multiple Formats and Multiple Storage Media
19.2.6. Checking Data Availability
19.2.7. Delayed Rendering with COleDataSource
19.2.8. COleDataSource and COleDataObject in Review
19.3. OLE Drag-and-Drop
19.3.1. Anatomy of a Drop Source
19.3.2. Anatomy of a Drop Target
19.3.3. MFC Support for OLE Drag-and-Drop
19.3.4. Drop Target Scrolling
19.4. Putting It All Together: The Widget Application
19.4.1. The AfxOleInit Function
Chapter 20. Automation
20.1. Automation Basics
20.1.1. IDispatch: The Root of All Automation
20.1.2. Automation Data Types
20.1.3. Late Binding vs. Early Binding
20.1.4. Dual Interfaces
20.1.5. Type Libraries
20.2. MFC Automation Servers
20.2.1. MFC, IDispatch, and Dispatch Maps
20.2.2. Writing an Automation Server
20.2.2.1. Adding Automation Methods
20.2.2.2. Adding Automation Properties
20.2.2.3. A Simple Automation Server
20.2.3. Automation Hierarchies
20.2.4. A More Complex Automation Server
20.2.4.1. The AfxThrowOleDispatchException Function
20.3. MFC Automation Clients
20.3.1. The PieClient Application
20.3.2. Connecting to a Running Automation Server
Chapter 21. ActiveX Controls
21.1. ActiveX Control Basics
21.2. Building ActiveX Controls
21.3. Using ActiveX Controls in MFC Applications
21.4. Advanced Topics