About This Electronic Book
Acknowledgments
Programming Microsoft Visual C++, Fifth Edition
Chapter One -- Microsoft Windows and Visual C++
The Windows Programming Model
The Visual C++ Components
Chapter Two -- The Microsoft Foundation Class Library Application Framework
Why Use the Application Framework?
What's an Application Framework?
MFC Library Message Mapping
Documents and Views
Chapter Three -- Getting Started with AppWizard -- "Hello, world!"
What's a View?
Single Document Interface vs. Multiple Document Interface
The "Do-Nothing" Application -- EX03A
The CEx03aView View Class
Drawing Inside the View Window -- The Windows Graphics Device Interface
A Preview of the Resource Editors
Win32 Debug Target vs. Win32 Release Target
Enabling the Diagnostic Macros
Understanding Precompiled Headers
Two Ways to Run a Program
Chapter Four -- Basic Event Handling, Mapping Modes, and a Scrolling View
Getting User Input -- Message Map Functions
Mapping Modes
A Scrolling View Window
Other Windows Messages
Chapter Five -- The Graphics Device Interface, Colors, and Fonts
The Device Context Classes
GDI Objects
Windows Color Mapping
Fonts
The EX05A Example
The EX05B Example
The EX05C Example -- CScrollView Revisited
Chapter Six -- The Modal Dialog and Windows Common Controls
Modal vs. Modeless Dialogs
Resources and Controls
Programming a Modal Dialog
The Dialog That Ate Cincinnati -- The EX06A Example
Enhancing the Dialog Program
Identifying Controls: CWnd Pointers and Control IDs
Setting the Color for the Dialog Background and for Controls
Painting Inside the Dialog Window
Adding Dialog Controls at Runtime
Using Other Control Features
Windows Common Controls
The EX06B Example
Chapter Seven -- The Modeless Dialog and Windows Common Dialogs
Modeless Dialogs
The CFormView Class -- A Modeless Dialog Alternative
The Windows Common Dialogs
Chapter Eight -- Using ActiveX Controls
ActiveX Controls vs. Ordinary Windows Controls
Installing ActiveX Controls
The Calendar Control
ActiveX Control Container Programming
The EX08A Example -- An ActiveX Control Dialog Container
ActiveX Controls in HTML Files
Creating ActiveX Controls at Runtime
The EX08B Example -- The Web Browser ActiveX Control
The EX08C Example -- A Complete Dual-Window Web Browser
Picture Properties
Bindable Properties -- Change Notifications
Other ActiveX Controls
Chapter Nine -- Internet Explorer 4 Common Controls
An Introduction to the New Internet Explorer 4 Common Controls
The EX09A Example
Chapter Ten -- Win32 Memory Management
Processes and Memory Space
How Virtual Memory Works
The VirtualAlloc Function -- Committed and Reserved Memory
The Windows Heap and the GlobalAlloc Function Family
The Small-Block Heap, the C++ new and delete Operators, and _heapmin
Memory-Mapped Files
Accessing Resources
Some Tips for Managing Dynamic Memory
Optimizing Storage for Constant Data
Chapter Eleven -- Bitmaps
GDI Bitmaps and Device-Independent Bitmaps
Using GDI Bitmaps
Using Bitmaps to Improve the Screen Display
DIBs and the CDib Class
Going Further with DIBs
Putting Bitmaps on Pushbuttons
Chapter Twelve -- Windows Message Processing and Multi-threaded Programming
Windows Message Processing
On-Idle Processing
Multithreaded Programming
Chapter Thirteen -- Menus, Keyboard Accelerators, the Rich Edit Control, and Property Sheets
The Main Frame Window and Document Classes
Windows Menus
Keyboard Accelerators
Command Processing
The Application Framework's Built-In Menu Items
MFC Text Editing Options
The EX13A Example
Property Sheets
The EX13A Example Revisited
The CMenu Class
Creating Floating Pop-Up Menus
Extended Command Processing
Chapter Fourteen -- Toolbars and Status Bars
Control Bars and the Application Framework
The Toolbar
ToolTips
Locating the Main Frame Window
The EX14A Toolbar Example
The Status Bar
The EX14B Status Bar Example
The Internet Explorer Rebar Toolbar
The EX14C Rebar Example
Chapter Fifteen -- A Reusable Frame Window Base Class
Why Reusable Base Classes Are Difficult to Write
The CPersistentFrame Class
The CFrameWnd Class and the ActivateFrame Member Function
The PreCreateWindow Member Function
The Windows Registry
Using the CString Class
The Position of a Maximized Window
Control Bar Status and the Registry
Static Data Members
The Default Window Rectangle
The EX15A Example
Persistent Frames in MDI Applications
Chapter Sixteen -- Separating the Document from Its View
Document-View Interaction Functions
The Simplest Document-View Application
The CFormView Class
The CObject Class
Diagnostic Dumping
The EX16A Example
A More Advanced Document-View Interaction
The CDocument::DeleteContents Function
The CObList Collection Class
The EX16B Example
Two Exercises for the Reader
Chapter Seventeen -- Reading and Writing Documents -- SDI Applications
Serialization -- What Is It?
The SDI Application
The EX17A Example -- SDI with Serialization
Explorer Launch and Drag and Drop
Chapter Eighteen -- Reading and Writing Documents -- MDI Applications
The MDI Application
The EX18A Example
Chapter Nineteen -- Printing and Print Preview
Windows Printing
Print Preview
Programming for the Printer
The EX19A Example -- A Wysiwyg Print Program
Template Collection Classes Revisited -- The CArray Class
The EX19B Example -- A Multipage Print Program
Chapter Twenty -- Splitter Windows and Multiple Views
The Splitter Window
View Options
Dynamic and Static Splitter Windows
The EX20A Example -- A Single View Class SDI Dynamic Splitter
The EX20B Example -- A Double View Class SDI Static Splitter
The EX20C Example -- Switching View Classes Without a Splitter
The EX20D Example -- A Multiple View Class MDI Application
Chapter Twenty-One -- Context-Sensitive Help
The Windows WinHelp Program
The Application Framework and WinHelp
A Help Example -- No Programming Required
The MAKEHELP Process
Help Command Processing
A Help Command Processing Example -- EX21B
Chapter Twenty-Two -- Dynamic Link Libraries
Fundamental DLL Theory
MFC DLLs -- Extension vs. Regular
A Custom Control DLL
Chapter Twenty-Three -- MFC Programs Without Document or View Classes
The EX23A Example -- A Dialog-Based Application
The EX23B Example -- An SDI Application
The EX23C Example -- An MDI Application
Chapter Twenty-Four -- The Component Object Model
ActiveX Technology Background
The Component Object Model
Real COM with the MFC Library
Containment and Aggregation vs. Inheritance
Chapter Twenty-Five -- Automation
Connecting C++ with Visual Basic for Applications
Automation Clients and Automation Components
Microsoft Excel -- A Better Visual Basic than Visual Basic
Properties, Methods, and Collections
The Problem That Automation Solves
The IDispatch Interface
Automation Programming Choices
An MFC Automation Component
An MFC Automation Client Program
An Automation Client Program Using the Compiler's #import Directive
The VARIANT Type
The COleVariant Class
Automation Examples
VBA Early Binding
Chapter Twenty-Six -- Uniform Data Transfer -- Clipboard Transfer and OLE Drag and Drop
The IDataObject Interface
The FORMATETC and STGMEDIUM Structures
MFC Uniform Data Transfer Support
The MFC CRectTracker Class
The EX26A Example -- A Data Object Clipboard
MFC Drag and Drop
The EX26B Example -- OLE Drag and Drop
Windows Applications and Drag and Drop -- Dobjview
Conclusion
Chapter Twenty-Seven -- Structured Storage
Compound Files
Storages and the IStorage Interface
Streams and the IStream Interface
The ILockBytes Interface
The EX27A Example -- Structured Storage
Structured Storage and Persistent COM Objects
The EX27B Example -- A Persistent DLL Component
The EX27C Example -- A Persistent Storage Client Program
Compound File Fragmentation
Other Compound File Advantages
Chapter Twenty-Eight -- OLE Embedded Components and Containers
Embedding vs. In-Place Activation (Visual Editing)
Mini-Servers vs. Full Servers (Components) -- Linking
The Dark Side of Visual Editing
Windows Metafiles and Embedded Objects
The MFC OLE Architecture for Component Programs
The EX28A Example -- An MFC In-Place-Activated Mini-Server
Container-Component Interactions
Component States
An Interface Summary
OLE Helper Functions
An OLE Embedding Container Application
The EX28B Example -- An Embedding Container
The EX28C Example -- An OLE Embedded Component
Chapter Twenty-Nine -- Introducing the Active Template Library
Revisiting COM
Writing COM Code
The COM Infrastructure
The ATL Roadmap
Client-Side ATL Programming
Server-Side ATL Programming
Conclusion
Chapter Thirty -- ATL and ActiveX Controls
ActiveX Controls
Using ATL to Write a Control
Conclusion
Chapter Thirty-One -- Database Management with Microsoft ODBC
The Advantages of Database Management
Structured Query Language
The ODBC Standard
The MFC ODBC Classes -- CRecordset and CDatabase
The Student Registration Database
The EX31A Recordset Example
The EX31A Program Elements
Filter and Sort Strings
Joining Two Database Tables
The MFC CRecordView Class
The EX31B Record View Example
Multiple Recordsets
ODBC Multithreading
Bulk Row Fetches
Using Recordsets Without Binding
Chapter Thirty-Two -- Database Management with Microsoft Data Access Objects
DAO, COM, and the Microsoft Jet Database Engine
DAO and VBA
DAO and MFC
What Databases Can You Open with DAO?
Using DAO in ODBC Mode -- Snapshots and Dynasets
DAO Table-Type Recordsets
DAO QueryDefs and TableDefs
DAO Multithreading
Displaying Database Rows in a Scrolling Window
Programming a Dynamic Recordset
The EX32A Example
The EX32A Resource File
Running the EX32A Program
Chapter Thirty-Three -- The OLE DB Templates
Why OLE DB?
Basic OLE DB Architecture
Basic OLE DB Template Architecture
Creating an OLE DB Consumer
Using the OLE DB Consumer Code
Creating an OLE DB Provider
Conclusion
Chapter Thirty-Four -- TCP/IP, Winsock, and WinInet
To COM or Not to COM
Internet Primer
Build Your Own $99 Intranet
Winsock
Building a Web Server with CHttpBlockingSocket
Building a Web Client with CHttpBlockingSocket
WinInet
Building a Web Client with the MFC WinInet Classes
Asynchronous Moniker Files
Chapter Thirty-Five -- Programming the Microsoft Internet Information Server
IIS Alternatives
Microsoft IIS
ISAPI Server Extensions
A Practical ISAPI Server Extension -- ex35a.dll
ISAPI Database Access
Using HTTP Cookies to Link Transactions
WWW Authentication
ISAPI Filters
A Sample ISAPI Filter -- ex35b.dll, ex35c.exe
Chapter Thirty-Six -- ActiveX Document Servers and the Internet
ActiveX Document Theory
ActiveX Document Server Example EX36A
ActiveX Document Server Example EX36B
Going Further with ActiveX Document Servers
Chapter Thirty-Seven -- Introducing Dynamic HTML
The DHTML Object Model
Visual C++ and DHTML
Chapter Thirty-Eight -- Visual C++ for Windows CE
Visual C++ for Windows CE
For More Information on Windows CE...
About Microsoft Press
Appendix A -- Message Map Functions in the Microsoft Foundation Class Library
Appendix B -- MFC Library Runtime Class Identification and Dynamic Object Creation
Getting an Object's Class Name at Runtime
The MFC CRuntimeClass Structure and the RUNTIME_CLASS Macro
Dynamic Creation
A Sample Program
Figure 1-1
Figure 1-2
Figure 1-3
Figure 2-1
Figure 4-2
Figure 4-3
Figure 4-4
Figure 5-1
Figure 6-1
Figure 6-2
Figure 7-1
Figure 8-1
Figure 9-1
Figure 10-1
Figure 10-2
Figure 11-1
Figure 13-1
Figure 13-2
Figure 13-3
Figure 14-2
Figure 14-3
Figure 14-4
Figure 14-5
Figure 14-6
Figure 14-7
Figure 14-8
Figure 14-9
Figure 16-1
Figure 16-3
Figure 17-1
Figure 17-3
Figure 18-4
Figure 18-1
Figure 18-2
Figure 18-3
Figure 19-1
Figure 19-2
Figure 20-1
Figure 20-2
Figure 24-5
Figure 24-6
Figure 25-1
Figure 25-2
Figure 25-3
Figure 26-1
Figure 26-2
Figure 26-4
Figure 27-1
Figure 27-3
Figure 28-1
Figure 28-2
Figure 28-3
Figure 28-4
Figure 28-5
Figure 29-1
Figure 29-2
Figure 29-4
Figure 31-1
Figure 31-2
Figure 31-3
Figure 31-5
Figure 32-2
Figure 34-1
Figure 34-2
Figure 34-3
Figure 34-4
Figure 34-6
Figure 34-7
Figure 34-8
Figure 35-1
Figure 35-2
Figure 35-3
Figure 35-4
Figure 35-5
Figure 35-6
Figure 36-1
Figure 36-3
Figure 37-1
Figure 37-3
Figure 37-4
Figure 4-4
Figure 4-4
Figure 38-4
Figure 38-5
Figure 38-6
Figure 38-7
Figure 38-7
Figure 38-7
Figure 38-8a
Figure 38-8b
Figure 38-9
Figure 38-10
Figure 38-11
Figure 38-12
Graphic 3-1
Graphic 3-2
Graphic 3-3
Graphic 3-7
Graphic 4-2
Graphic 4-4
Graphic 5-3
Graphic 5-5
Graphic 6-3
Graphic 6-11
Graphic 6-12
Graphic 6-15
Graphic 6-19
Graphic 7-5
Graphic 8-3
Graphic 8-4
Graphic 8-5
Graphic 8-7
Graphic 8-8
Graphic 9-2
Graphic 9-11
Graphic 9-12
Graphic 9-13
Graphic 11-2
Graphic 11-4
Graphic 13-3
Graphic 13-5
Graphic 14-5
Graphic 14-8
Graphic 15-3
Graphic 16-1
Graphic 16-5
Graphic 17-2
Graphic 19-2
Graphic 19-3
Graphic 19-4
Graphic 19-6
Graphic 19-7
Graphic 20-2
Graphic 20-3
Graphic 21-1
Graphic 21-2
Graphic 21-3
Graphic 21-11
Graphic 21-12
Graphic 21-13
Graphic 21-14
Graphic 22-1
Graphic 22-2
Graphic 22-3
Graphic 23-1
Graphic 23-2
Graphic 23-3
Graphic 24-1
Graphic 24-2
Graphic 24-5
Graphic 24-6
Graphic 25-1
Graphic 25-6
Graphic 25-7
Graphic 25-8
Graphic 25-9
Graphic 25-12
Graphic 26-1
Graphic 28-1
Graphic 28-6
Graphic 28-7
Graphic 31-1
Graphic 31-2
Graphic 31-6
Graphic 31-7
Graphic 31-11
Graphic 31-12
Graphic 32-1
Graphic 34-1
Graphic 35-1
Graphic 35-3
Graphic 35-4
Graphic 37-1

Introduction
MFC, ATL, and WFC—Is MFC Dead?
C++ vs. Java
Who Can Use This Book
What's Not Covered
How to Use This Book
The Organization of This Book
Win32 vs. Win16
Windows 95 and Windows 98 vs. Windows NT
Going Further with Windows: The "For Win32 Programmers" Sidebars
Using the Companion CD-ROM
Technical Notes and Sample Programs
Support