logo资料库

Programming windows with MFC.pdf

第1页 / 共1403页
第2页 / 共1403页
第3页 / 共1403页
第4页 / 共1403页
第5页 / 共1403页
第6页 / 共1403页
第7页 / 共1403页
第8页 / 共1403页
资料共1403页,剩余部分请下载后查看
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
该 pdf 由 Cylee 制作,适合于一面两页,双面打印 1.2. 1.2.1. 1.2.2. 1.2.3. 1.2.4. 1.2.5. Introduction................................................................................................1 What's New in the Second Edition ................................................................ 2 What's On the CD ........................................................................................... 4 From Me to You (and You to Me) .................................................................. 4 PART Ⅰ: Fundamental of Windows and MFC......................................6 Chapter 1. Hello, MFC............................................................................6 1.1. The Windows Programming Model ................................................... 7 1.1.1. Messages, Messages, and More Messages................................................9 1.1.2. Windows Programming, SDK-Style....................................................... 11 Hungarian Notation and Windows Data Types.......................................16 1.1.3. 1.1.4. SDK Programming in Perspective ..........................................................17 Introducing MFC............................................................................... 18 The Benefits of Using C++ and MFC.....................................................19 The MFC Design Philosophy..................................................................20 The Document/View Architecture ..........................................................21 The MFC Class Hierarchy ......................................................................22 AFX Functions........................................................................................23 1.3. Your First MFC Application............................................................. 23 The Application Object...........................................................................26 1.3.1. How MFC Uses the Application Object .................................................29 1.3.2. The Frame Window Object.....................................................................31 1.3.3. Painting the Window...............................................................................34 1.3.4. The Message Map...................................................................................37 1.3.5. 1.3.6. How Message Maps Work......................................................................39 1.3.7. Windows, Character Sets, and the _T Macro..........................................42 1.3.8. Building the Application.........................................................................44 The Big Picture .......................................................................................45 1.3.9. Chapter 2. Drawing in a Window .........................................................48 2.1. The Windows GDI ............................................................................. 49 The MFC Device Context Classes ..........................................................50 Device Context Attributes.......................................................................54 The Drawing Mode.................................................................................56 The Mapping Mode.................................................................................58 2.2. Drawing with the GDI....................................................................... 68 Drawing Lines and Curves......................................................................69 2.2.1. Drawing Ellipses, Polygons, and Other Shapes ......................................73 2.2.2. GDI Pens and the CPen Class .................................................................76 2.2.3. GDI Brushes and the CBrush Class ........................................................81 2.2.4. Drawing Text...........................................................................................85 2.2.5. GDI Fonts and the CFont Class ..............................................................88 2.2.6. Raster Fonts vs. TrueType Fonts.............................................................91 2.2.7. Rotated Text ............................................................................................91 2.2.8. 2.2.9. Stock Objects ..........................................................................................93 2.2.10. Deleting GDI Objects..............................................................................95 2.2.11. Deselecting GDI Objects ........................................................................96 2.2.12. The Ruler Application.............................................................................98 Seeing What You've Drawn............................................................. 101 Adding a Scroll Bar to a Window .........................................................102 Setting a Scroll Bar's Range, Position, and Page Size...........................103 Synchronizing the Thumb Size and the Window Size ..........................106 Processing Scroll Bar Messages............................................................107 Scrolling a Window...............................................................................109 2.1.2. 2.1.3. 2.1.4. 2.1.5. 2.3. 2.3.1. 2.3.2. 2.3.3. 2.3.4. 2.3.5. 1
该 pdf 由 Cylee 制作,适合于一面两页,双面打印 2.3.6. 3.3.1. 3.3.2. 3.3.3. 4.1.1. 4.1.2. 4.1.3. 4.1.4. 4.1.5. 4.1.6. 4.1.7. 4.2.1. 4.2.2. 4.2.3. 4.2.4. 3.2.1. 3.2.2. 3.2.3. 3.2.4. 3.2.5. 3.2.6. 3.2.7. The Accel Application ...........................................................................111 2.4. Loose Ends ........................................................................................120 Chapter 3. The Mouse and the Keyboard...........................................122 3.1. Getting Input from the Mouse ........................................................123 3.1.1. More About the TicTac Window........................................................... 146 The PostNcDestroy Function................................................................ 148 3.1.2. Nonclient-Area Mouse Messages......................................................... 149 3.1.3. 3.1.4. The WM_NCHITTEST Message ......................................................... 152 The WM_MOUSELEAVE and WM_MOUSEHOVER Messages ...... 153 3.1.5. 3.2. Getting Input from the Keyboard...................................................173 The Input Focus.................................................................................... 173 Keystroke Messages ............................................................................. 175 Virtual Key Codes ................................................................................ 178 Shift States and Toggles........................................................................ 180 Character Messages.............................................................................. 182 Dead-Key Messages ............................................................................. 185 The Caret .............................................................................................. 186 3.3. The VisualKB Application...............................................................190 Handling the Caret................................................................................ 202 Entering and Editing Text..................................................................... 206 Other Points of Interest......................................................................... 207 Chapter 4. Menus ................................................................................209 4.1. Menu Basics ......................................................................................210 Creating a Menu ....................................................................................211 Loading and Displaying a Menu .......................................................... 214 Responding to Menu Commands ......................................................... 217 Command Ranges................................................................................. 218 Updating the Items in a Menu .............................................................. 220 Update Ranges...................................................................................... 224 Keyboard Accelerators ......................................................................... 225 4.2. The Shapes Application ...................................................................228 Running the MFC AppWizard.............................................................. 245 Analyzing AppWizard's Output............................................................ 248 Beyond AppWizard .............................................................................. 252 The Process in Review ......................................................................... 258 4.3. Menu Magic ......................................................................................259 4.3.1. Creating Menus Programmatically....................................................... 259 4.3.2. Modifying Menus Programmatically.................................................... 260 4.3.3. The System Menu................................................................................. 262 Owner-Draw Menus ............................................................................. 265 4.3.4. OnMenuChar Processing...................................................................... 269 4.3.5. Cascading Menus.................................................................................. 271 4.3.6. 4.3.7. Context Menus ..................................................................................... 272 The TPM_RETURNCMD Flag............................................................ 276 4.3.8. 4.4. The Colors Application ....................................................................277 The Context Menu................................................................................ 302 On Your Own........................................................................................ 304 Chapter 5. The MFC Collection Classes ............................................307 5.1. Arrays................................................................................................307 The MFC Array Classes ....................................................................... 308 Dynamic Array Sizing .......................................................................... 312 Creating Type-Safe Array Classes with CArray ................................... 315 5.1.1. 5.1.2. 5.1.3. 4.4.1. 4.4.2. 2
该 pdf 由 Cylee 制作,适合于一面两页,双面打印 5.2.1. 5.2.2. 6.1.1. 6.1.2. 6.1.3. 6.1.4. 6.2. 5.3.1. 5.3.2. 5.3.3. 5.3.4. 5.2. Lists................................................................................................... 317 The MFC List Classes...........................................................................318 Creating Type-Safe List Classes with CList..........................................322 5.3. Maps.................................................................................................. 324 The MFC Map Classes..........................................................................324 How Maps Work ...................................................................................326 Optimizing Lookup Efficiency .............................................................328 Creating Type-Safe Map Classes with CMap .......................................330 5.4. The Typed Pointer Classes .............................................................. 331 Chapter 6. File I/O and Serialization .................................................335 6.1. The CFile Class ................................................................................ 335 Opening, Closing, and Creating Files ...................................................336 Reading and Writing .............................................................................339 CFile Derivatives ..................................................................................341 Enumerating Files and Folders..............................................................343 Serialization and the CArchive Class ............................................. 346 6.2.1. Serialization Basics...............................................................................347 6.2.2. Writing Serializable Classes..................................................................349 Versioning Serializable Classes: Versionable Schemas.........................351 6.2.3. 6.2.4. How Serialization Works ......................................................................354 Serializing CObjects .............................................................................360 6.2.5. Chapter 7. Controls .............................................................................363 7.1. The Classic Controls........................................................................ 364 The CButton Class ................................................................................367 The CListBox Class...............................................................................373 The CStatic Class ..................................................................................382 The FontView Application....................................................................386 The CEdit Class ....................................................................................395 The CComboBox Class ......................................................................... 411 The CScrollBar Class............................................................................416 7.2. Advanced Control Programming ................................................... 417 Numeric Edit Controls ..........................................................................418 7.2.1. Owner-Draw List Boxes .......................................................................419 7.2.2. Graphical Push Buttons.........................................................................430 7.2.3. Customizing a Control's Colors ............................................................431 7.2.4. 7.2.5. Message Reflection...............................................................................439 Chapter 8. Dialog Boxes and Property Sheets....................................443 8.1. Modal Dialog Boxes and the CDialog Class................................... 444 The Dialog Box Template .....................................................................444 The CDialog Class ................................................................................452 Creating a Modal Dialog Box ...............................................................456 Dialog Data Exchange and Dialog Data Validation ..............................458 Interacting with the Controls in a Dialog..............................................466 The DlgDemo1 Application..................................................................468 8.2. Modeless Dialog Boxes .................................................................... 480 The DlgDemo2 Application..................................................................480 8.3. Using a Dialog Box as a Main Window.......................................... 494 Processing Keyboard Messages ............................................................507 Preprocessing WM_COMMAND Messages ........................................509 8.4. Property Sheets ................................................................................ 510 The PropDemo Application ..................................................................514 7.1.1. 7.1.2. 7.1.3. 7.1.4. 7.1.5. 7.1.6. 7.1.7. 8.1.1. 8.1.2. 8.1.3. 8.1.4. 8.1.5. 8.1.6. 8.2.1. 8.3.1. 8.3.2. 8.4.1. 3
该 pdf 由 Cylee 制作,适合于一面两页,双面打印 10.1. 9.2.1. 9.2.2. 8.5. The Common Dialogs.......................................................................529 8.5.1. Modifying the Common Dialogs.......................................................... 531 8.5.2. The Phones Application........................................................................ 533 PART Ⅱ: The Documents/View Architecture.....................................549 Chapter 9. Documents, Views, and the Single Document Interface .549 9.1. Document/View Fundamentals .......................................................550 The InitInstance Function Revisited..................................................... 552 9.1.1. The Document Object........................................................................... 554 9.1.2. The View Object................................................................................... 560 9.1.3. The Frame Window Object................................................................... 564 9.1.4. 9.1.5. Dynamic Object Creation ..................................................................... 564 9.1.6. More on the SDI Document Template.................................................. 566 Registering Document Types with the Operating System Shell ........... 568 9.1.7. Command Routing................................................................................ 569 9.1.8. 9.1.9. Predefined Command IDs and Command Handlers............................. 572 9.2. Your First Document/View Application .........................................575 The SdiSquares Application ................................................................. 575 SdiSquares Step by Step ....................................................................... 595 9.3. Doc + View = Less Work for You ....................................................597 Chapter 10. Scroll Views, HTML Views, and Other View Types......599 Scroll Views ...................................................................................600 10.1.1. CScrollView Basics............................................................................... 600 10.1.2. CScrollView Operations........................................................................ 605 10.1.3. Optimizing Scrolling Performance....................................................... 605 10.1.4. The ScrollDemo Application................................................................ 607 10.1.5. Converting an Ordinary View into a Scroll View................................. 615 HTML Views.................................................................................615 10.2.1. CHtmlView Operations ......................................................................... 616 10.2.2. CHtmlView Overridables ...................................................................... 618 10.2.3. Utilizing DHTML in CHtmlView-Based Applications ......................... 620 Tree Views .....................................................................................626 10.3.1. Initializing a Tree View ........................................................................ 627 10.3.2. Tree View Member Functions and Notifications.................................. 630 10.3.3. The DriveTree Application................................................................... 632 List Views ......................................................................................644 10.4.1. Initializing a List View ......................................................................... 645 10.4.2. Changing the Presentation Style........................................................... 648 10.4.3. Sorting in a List View........................................................................... 649 10.4.4. Hit-Testing in a List View..................................................................... 650 10.4.5. The WinDir Application ....................................................................... 651 Do-It-Yourself Control Views ......................................................665 Chapter 11. Multiple Documents and Multiple Views......................669 11.1. MFC and the Multiple Document Interface...............................669 Synchronizing Multiple Views of a Document..................................... 672 11.1.1. The MdiSquares Application................................................................ 675 11.1.2. 11.1.3. Supporting Multiple Document Types.................................................. 694 11.1.4. Alternatives to MDI.............................................................................. 695 Splitter Windows ..........................................................................696 11.2.1. Dynamic Splitter Windows................................................................... 698 The Sketch Application ........................................................................ 700 11.2.2. 11.2.3. Static Splitter Windows ........................................................................ 718 10.5. 10.2. 10.3. 10.4. 11.2. 4
该 pdf 由 Cylee 制作,适合于一面两页,双面打印 12.4. 13.1. 12.3. 12.2. 12.1. The Wanderer Application ....................................................................719 11.2.4. 11.2.5. Custom Command Routing...................................................................749 11.2.6. Three-Way Splitter Windows................................................................751 11.2.7. Dynamic Splitter Windows with Multiple View Types.........................753 Chapter 12. Toolbars, Status Bars, and Rebars ................................755 Toolbars ........................................................................................ 755 12.1.1. Creating and Initializing a Toolbar........................................................756 12.1.2. Docking and Floating............................................................................762 12.1.3. Controlling a Toolbar's Visibility ..........................................................766 12.1.4. Keeping Toolbar Buttons in Sync with Your Application .....................768 12.1.5. Adding ToolTips and Flyby Text ..........................................................770 12.1.6. Adding Non-Push-Button Controls to a Toolbar...................................774 12.1.7. Updating Non-Push-Button Controls....................................................775 12.1.8. Making Toolbar Settings Persistent.......................................................777 12.1.9. Toolbar Support in AppWizard .............................................................777 Status Bars.................................................................................... 778 12.2.1. Creating and Initializing a Status Bar ...................................................779 12.2.2. Providing Context-Sensitive Help for Menu Items...............................782 12.2.3. Creating Custom Status Bar Panes........................................................783 12.2.4. Status Bar Support in AppWizard .........................................................786 Putting It All Together: The MyWord Application................... 787 12.3.1. The Main Toolbar..................................................................................807 12.3.2. The Style Bar ........................................................................................808 12.3.3. More About CRichEditView..................................................................813 Rebars ........................................................................................... 814 Chapter 13. Printing and Print Previewing ......................................817 Printing with Documents and Views .......................................... 817 13.1.1. The Windows Print Architecture...........................................................818 13.1.2. The MFC Print Architecture .................................................................825 13.1.3. Print Previewing....................................................................................834 A Bare-Bones Printing Application ............................................ 835 13.2.1. Black-and-White Print Previews...........................................................841 A More Complex Printing Application ...................................... 842 13.3.1. A Unique Approach to Serialization .....................................................856 Printing Tips and Tricks.............................................................. 857 13.4.1. Using the Print Dialog's Selection Button.............................................857 13.4.2. Assume Nothing—And Test Thoroughly! ............................................858 13.4.3. Adding Default Pagination Support......................................................861 13.4.4. Enumerating Printers.............................................................................862 PART Ⅲ: Beyong the Basics ................................................................865 Chapter 14. Timers and Idle Processing ...........................................865 Timer............................................................................................. 865 14.1.1. Setting a Timer: Method 1 ....................................................................866 14.1.2. Responding to WM_TIMER Messages ................................................869 14.1.3. Setting a Timer: Method 2 ....................................................................872 Stopping a Timer...................................................................................874 14.1.4. The Clock Application ................................................................. 875 14.2.1. Processing Timer Messages ..................................................................885 14.2.2. Getting the Current Time:The CTime Class ..........................................887 14.2.3. Using the MM_ISOTROPIC Mapping Mode.......................................888 14.2.4. Hiding and Displaying the Title Bar .....................................................890 13.2. 13.3. 13.4. 14.1. 14.2. 5
该 pdf 由 Cylee 制作,适合于一面两页,双面打印 Implementing Client-Area Drag........................................................... 892 14.2.5. 14.2.6. Using the System Menu as a Context Menu......................................... 893 14.2.7. Topmost Windows................................................................................ 895 14.2.8. Making Configuration Settings Persistent............................................ 896 14.2.9. Controlling the Window Size: The WM_GETMINMAXINFO Message 903 921 15.2. 15.1. 14.3. Idle Processing ..............................................................................904 14.3.1. Using OnIdle ........................................................................................ 906 14.3.2. Idle Processing vs. Multithreading ....................................................... 909 Chapter 15. Bitmaps, Palettes, and Regions..................................... 911 Palettes...........................................................................................912 15.1.1. How Windows Uses Color ................................................................... 912 15.1.2. Logical Palettes and the CPalette Class................................................ 914 15.1.3. Creating a Logical Palette..................................................................... 915 15.1.4. Realizing a Logical Palette................................................................... 919 15.1.5. Drawing with Palette Colors................................................................. 920 15.1.6. The WM_QUERYNEWPALETTE and WM_PALETTECHANGED Msg 15.1.7. Determining Whether a Logical Palette Is Needed............................... 924 15.1.8. The PaletteDemo Application............................................................... 926 15.1.9. Palette Animation ................................................................................. 932 The ::SetSystemPaletteUse Function ............................................... 937 15.1.10. Bitmaps..........................................................................................938 15.2.1. DDBs and the CBitmap Class............................................................... 938 15.2.2. Blitting Bitmaps to Screens and Other Devices.................................... 940 15.2.3. Bitmap Resources................................................................................. 943 15.2.4. DIBs and DIB Sections ........................................................................ 945 15.2.5. Blits, Raster Operations, and Color Mapping....................................... 947 15.2.6. The BitmapDemo Application.............................................................. 950 15.2.7. Writing a BMP File Viewer .................................................................. 965 15.2.8. More on the ::LoadImage Function...................................................... 981 Regions ..........................................................................................982 15.3.1. Regions and the CRgn Class................................................................. 983 15.3.2. The RegionDemo Application.............................................................. 988 Chapter 16. The Common Controls ..................................................993 Common Control Fundamentals.................................................994 16.1.1. Creating a Common Control................................................................. 997 16.1.2. Processing Notifications: The WM_NOTIFY Message ..................... 1000 Slider, Spin Button, and ToolTip Controls ...............................1004 Slider Controls.................................................................................... 1004 16.2.1. 16.2.2. Spin Button Controls .......................................................................... 1009 16.2.3. ToolTip Controls................................................................................. 1013 16.2.4. The GridDemo Application ................................................................ 1018 Image Lists and ComboBoxEx Controls ..................................1028 16.3.1. Image Lists ......................................................................................... 1029 16.3.2. ComboBoxEx Controls ...................................................................... 1032 16.3.3. The PathList Application.................................................................... 1036 Progress Controls and Animation Controls .............................1045 16.4.1. Progress Controls................................................................................ 1046 16.4.2. Animation Controls ............................................................................ 1048 IP Address Controls and Other Data-Entry Controls.............1050 16.5.1. IP Address Controls............................................................................ 1050 16.5.2. Hotkey Controls.................................................................................. 1052 16.1. 16.2. 15.3. 16.3. 16.4. 16.5. 6
该 pdf 由 Cylee 制作,适合于一面两页,双面打印 17.2. 17.1. 16.5.3. Month Calendar Controls....................................................................1053 16.5.4. Date-Time Picker Controls .................................................................1057 Chapter 17. Threads and Thread Synchronization.........................1061 Threads ....................................................................................... 1062 17.1.1. Creating a Worker Thread ...................................................................1063 17.1.2. Creating a UI Thread...........................................................................1066 Suspending and Resuming Threads ....................................................1067 17.1.3. 17.1.4. Putting Threads to Sleep .....................................................................1068 17.1.5. Terminating a Thread ..........................................................................1069 17.1.6. Autodeleting CWinThreads.................................................................1070 17.1.7. Terminating Another Thread ...............................................................1072 17.1.8. Threads, Processes, and Priorities.......................................................1075 17.1.9. Using C Run-Time Functions in Multithreaded Applications.............1080 Calling MFC Member Functions Across Thread Boundaries.........1081 17.1.10. 17.1.11. Your First Multithreaded Application .............................................1085 Thread Synchronization............................................................ 1093 17.2.1. Critical Sections..................................................................................1094 17.2.2. Mutexes...............................................................................................1096 17.2.3. Events..................................................................................................1098 17.2.4. Semaphores......................................................................................... 1102 17.2.5. The CSingleLock and CMultiLock Classes ......................................... 1104 17.2.6. Writing Thread-Safe Classes............................................................... 1107 17.2.7. The ImageEdit Application ................................................................. 1109 Odds and Ends ............................................................................1132 17.3.1. Message Pumps................................................................................... 1132 17.3.2. Launching Other Processes................................................................. 1134 17.3.3. File Change Notifications ................................................................... 1136 PART Ⅳ: COM, OLE and ActiveX....................................................1139 Chapter 18. MFC and the Component Object Model.....................1139 The Component Object Model ..................................................1140 Instantiating a COM Object ................................................................ 1142 18.1.1. 18.1.2. Object Lifetimes.................................................................................. 1144 18.1.3. Acquiring Interface Pointers ............................................................... 1145 18.1.4. COM Servers ...................................................................................... 1146 18.1.5. Location Transparency........................................................................ 1148 18.1.6. Object Linking and Embedding .......................................................... 1149 18.1.7. Active Documents............................................................................... 1152 18.1.8. ActiveX............................................................................................... 1153 18.2. MFC and COM ...........................................................................1154 18.2.1. Multiple Inheritance............................................................................ 1155 18.2.2. Nested Classes .................................................................................... 1157 18.2.3. MFC and Nested Classes .................................................................... 1161 18.2.4. How MFC Implements IUnknown...................................................... 1163 18.2.5. Interface Maps .................................................................................... 1165 18.2.6. MFC and Aggregation......................................................................... 1166 18.2.7. MFC and Class Factories .................................................................... 1169 18.2.8. Putting It All in Perspective ................................................................ 1171 Chapter 19. The Clipboard and OLE Drag-and-Drop ................... 1173 The Legacy Clipboard ................................................................1174 19.1.1. Clipboard Formats .............................................................................. 1176 19.1.2. Private Clipboard Formats .................................................................. 1181 19.1.3. Providing Data in Multiple Formats ................................................... 1182 19.1.4. Querying for Available Data Formats ................................................. 1183 17.3. 18.1. 19.1. 7
该 pdf 由 Cylee 制作,适合于一面两页,双面打印 19.3. 19.4. 20.1. 19.2. 19.1.5. Delayed Rendering ..............................................................................1185 19.1.6. Building a Reusable Clipboard Class ..................................................1189 The OLE Clipboard ................................................................... 1189 19.2.1. OLE Clipboard Basics.........................................................................1190 19.2.2. MFC, Global Memory, and the OLE Clipboard ..................................1196 19.2.3. Using Alternative Storage Media.........................................................1198 19.2.4. Treating the OLE Clipboard as a CFile .............................................. 1200 19.2.5. Multiple Formats and Multiple Storage Media................................... 1202 19.2.6. Checking Data Availability................................................................. 1203 19.2.7. Delayed Rendering with COleDataSource......................................... 1204 19.2.8. COleDataSource and COleDataObject in Review............................. 1208 OLE Drag-and-Drop..................................................................1209 19.3.1. Anatomy of a Drop Source..................................................................1211 19.3.2. Anatomy of a Drop Target.................................................................. 1215 19.3.3. MFC Support for OLE Drag-and-Drop .............................................. 1218 19.3.4. Drop Target Scrolling ......................................................................... 1221 Putting It All Together: The Widget Application.....................1221 19.4.1. The AfxOleInit Function .................................................................... 1245 Chapter 20. Automation ..................................................................1247 Automation Basics......................................................................1248 20.1.1. IDispatch: The Root of All Automation.............................................. 1250 20.1.2. Automation Data Types ...................................................................... 1252 20.1.3. Late Binding vs. Early Binding .......................................................... 1259 20.1.4. Dual Interfaces ................................................................................... 1260 20.1.5. Type Libraries..................................................................................... 1261 20.2. MFC Automation Servers..........................................................1263 20.2.1. MFC, IDispatch, and Dispatch Maps ................................................. 1264 20.2.2. Writing an Automation Server............................................................ 1266 20.2.3. Automation Hierarchies...................................................................... 1274 20.2.4. A More Complex Automation Server................................................. 1276 20.3. MFC Automation Clients...........................................................1302 20.3.1. The PieClient Application .................................................................. 1303 20.3.2. Connecting to a Running Automation Server..................................... 1316 Chapter 21. ActiveX Controls..........................................................1319 ActiveX Control Basics ..............................................................1321 Building ActiveX Controls .........................................................1333 Using ActiveX Controls in MFC Applications .........................1375 Advanced Topics.........................................................................1386 21.1. 21.2. 21.3. 21.4. 8
分享到:
收藏