Introduction<br />Foreword<br />About the Author<br />Core MFC<br />The MFC Architecture<br />A Brief History of MFC<br />The MFC Class Hierarchy<br />CObject<br />CCmdTarget<br />CWinThread<br />CWinApp<br />CWnd<br />CFrameWnd<br />CView<br />CDocument<br />Summary<br />MFC Dialogs, Controls, and Data Interaction<br />Creating an Application<br />Starting and Using MFC AppWizard<br />The AppWizard-Generated Code<br />Modifying the Application<br />Adding Dialog Controls<br />Adding Initialization<br />Using Dialog Controls<br />ToolTips<br />Enabling ToolTips<br />Displaying Text<br />Dialog Data Exchange<br />Standard DDX<br />UpdateData<br />Using Standard Dialog Boxes<br />File Open/Save<br />Color Selector<br />Font Selector<br />Print Dialog<br />Summary<br />The Windows Common Controls<br />Initializing and Using the Common Controls<br />Notifications for Windows Common Controls<br />The Notification Message Structure<br />Overview of the Notification Process<br />A Better Notification Handling Scheme<br />Specifying Notification Ranges with ON_NOTIFY_RANGE<br />Hot Key Controls: Class CHotKeyCtrl<br />CHotKeyCtrl Class Methods<br />Creating and Initializing a CHotKeyCtrl Object<br />Using a Hot Key Control<br />Spin Controls: Class CSpinButtonCtrl<br />Spin Control Styles<br />CSpinButtonCtrl Messages<br />CSpinButtonCtrl Class Methods<br />Creating and Initializing a Spin Control<br />Sample Program: SPIN1<br />Slider Controls: Class CSliderCtrl<br />Slider Control Styles<br />CSliderCtrl Messages<br />CSliderCtrl Class Methods<br />Creating and Initializing a Slider Control<br />Sample Program: Slider Controls (SLIDER1)<br />Sample Program: SLIDER1<br />Progress Bar Controls: Class CProgressCtrl<br />CProgressCtrl Class Methods<br />Creating and Initializing a CProgressCtrl Object<br />Using a Progress Control<br />Image Lists: Class CImageList<br />CImageList Class Methods<br />Creating and Initializing a CImageList Control<br />List View Controls: Class CListCtrl<br />List View Control Styles<br />Image Lists and the List View Control<br />List View Items and Subitems<br />List View Notification Messages<br />Creating and Initializing a CListCtrl Object<br />Using the List View Control<br />Tree View Controls: Class CTreeCtrl<br />Tree View Control Styles<br />Tree View Notification Messages<br />CTreeCtrl Class Methods<br />Creating and Initializing a Tree View Control<br />Using a CTreeCtrl Object<br />Sample Program: TREELIST.EXE<br />Tab Controls: Class CTabCtrl<br />Tab Control Styles<br />Tab Control Notification Messages<br />CTabCtrl Class Methods<br />The Tab Item Structure (TC_ITEM)<br />Creating and Initializing a Tab Control<br />Using a Tab Control<br />Animate Controls: Class CAnimateCtrl<br />Animate Control Styles<br />Animate Control Notification Messages<br />CAnimateCtrl Class Methods<br />Creating and Initializing an Animate Control<br />Using an Animate Control<br />Rich Edit Controls: Class CRichEditCtrl<br />Rich Edit Control Window Styles<br />The Character Format Structure (CHARFORMAT)<br />The Paragraph Format Structure (PARAFORMAT)<br />CRichEditCtrl Class Methods<br />CRichEditCtrl Line-Related Methods<br />CRichEditCtrl Text-Selection Methods<br />CRichEditCtrl Formatting Methods<br />CRichEditCtrl Editing Methods<br />CRichEditCtrl Clipboard Methods<br />CRichEditCtrl General-Purpose Methods<br />Creating and Initializing a Rich Edit Control<br />Using a Rich Edit Control<br />Summary<br />Painting, Device Contexts, Bitmaps, and Fonts<br />Device Contexts<br />The Graphics Device Interface<br />MFC Wrapping<br />MFC Device Context Classes<br />The Base Class: CDC<br />Painting with Class CPaintDC<br />Managing Client Areas with Class CClientDC<br />Managing Frame Windows with Class CWindowDC<br />Windows Graphic Objects<br />Pens: Class CPen<br />Brushes: Class CBrush<br />Fonts: Class CFont<br />Bitmaps: Class CBitmap<br />Palettes: Class CPalette<br />Regions: Class CRgn<br />GDI Coordinate Systems<br />Logical Mapping Modes<br />Vector Graphics<br />Drawing Modes<br />Lines and Polylines<br />Rectangles<br />Regions<br />Polygons<br />Ellipses<br />Bezier Curves<br />Fonts and Text<br />Font Characteristics<br />The TEXTMETRIC Structure<br />The LOGFONT Structure<br />Font Creation<br />Drawing Text<br />Sample Program: Vector Graphics and Text Methods (VECTEXT1.EXE)<br />Raster Graphics<br />Named Raster Operations (ROPs)<br />Bitmaps<br />Device-Dependent Bitmaps<br />Device-Independent Bitmaps (DIBs)<br />The CBitmap Class<br />Transferring and Contorting Bitmaps<br />Bitmap Resources<br />Tacking Resources onto an Executable File<br />Getting Image Resources out of an Executable File<br />Sample Program: Exploring Bitmap Resources (BITMAP1)<br />Summary<br />Custom Control Development<br />Window Classes Versus C++ Classes<br />A Validating Edit Control<br />The Clock Static Control<br />Control Metrics<br />Painting the Face<br />Locating the Hands<br />Painting the Hands<br />Setting the Time<br />Pitfalls of Subclassing Standard Controls<br />The Hyperlink Control<br />Implementation Strategy<br />Font Processing<br />Painting the Window<br />Controlling the Cursor<br />Mouse Input<br />Keyboard Input<br />Launching the Link<br />Advanced Custom Control Topics<br />Subclassing Limitations<br />Notifications<br />Using the Resource Editor with Custom Classes<br />Summary<br />The MFC Application Object, Message Routing, and Idle Processing<br />The MFC Application Object<br />CWinApp and Application Lifetime<br />The CWinApp Data Members<br />The CWinApp Member Functions<br />Application-Specific Initialization<br />Functionality in InitInstance<br />OLE Container Support<br />3D Look for Windows NT 3.5x<br />Registry Usage<br />Most Recently Used Files List<br />SDI and MDI Document/View<br />Main Frame Window Creation<br />Automation Support<br />Rich Edit Control Support<br />Command-Line Handling<br />Message Routing, Message Maps, and Message Categories<br />Message Routing<br />PreTranslateMessage<br />Message Maps<br />Idle Processing<br />OnIdle<br />Idle Processing for Dialogs<br />The Splash Screen Component<br />Summary<br />Documents, Views, and Applications That Use Them<br />The Document/View Architecture<br />Documents, Frames, and Views<br />Document Templates<br />Creating New Documents<br />Opening New Files<br />Single Versus Multiple Document Templates<br />Views<br />The CView Class<br />The CScrollView Class<br />The CFormView Class<br />The Database View Classes<br />The Control Views<br />Changing Views in an SDI<br />Using the MDI<br />Summary<br />Extending the User Interface<br />Responding to the User<br />Keyboard Messaging<br />Handling Keyboard Messages<br />Mouse Messaging<br />Handling Mouse Messages<br />User Interfaces and AppWizard<br />Extending Menus<br />Obtaining Menus and Pop-up Menus<br />Adding Menu Items<br />Using Floating Pop-up Menus<br />Putting Control Bars to Use<br />Using Toolbars and Rebars<br />Using Status Bars<br />Showing and Hiding Control Bars<br />Supporting ToolTips<br />Updating the User Interface<br />Property Sheets and Wizards<br />MFC's Support for Property Sheets and Wizards<br />Creating a Simple Wizard<br />Splitting a View<br />Summary<br />Printing<br />Printing Fundamentals<br />Printing with MFC<br />Printing in the View<br />The PrintInfo Object<br />Printing Menu Commands<br />Printing and GDI Mapping Modes<br />WYSIWYG Printing<br />Application Resources<br />The Application Class<br />The View Class<br />Pagination<br />Printing with a Known Page Count<br />Printing with an Unknown Page Count<br />Printing Page Numbers<br />Stopping and Aborting Print Jobs<br />Halting a Print Job in OnPrepareDC()<br />Halting a Print Job in OnPrint()<br />Summary<br />MFC and COM Programming<br />COM<br />A Little History<br />Interfaces, Objects, and Methods<br />Some Terminology<br />A Real-World View<br />The IUnknown Interface<br />Servers, Clients, and Classes<br />The COM Runtime Environment<br />Defining the Class Factory<br />How Are COM Objects Reused?<br />Marshaling and Threading<br />Marshaling<br />Threading<br />COM, OLE, and Automation<br />IDispatch<br />Automation Servers, Objects, and Controllers<br />Supporting Both IDispatch and IUnknown<br />Persisting COM Data<br />Structured Storage<br />Identifying COM Data (Monikers)<br />Transferring Data<br />Uniform Data Transfer<br />Connectable Objects<br />DCOM<br />Object Creation<br />Invoking Methods<br />Security Issues<br />Some Important Information<br />BSTR<br />SAFEARRAY<br />HRESULT<br />VARIANT<br />Further Reading<br />Summary<br />COM and MFC<br />Understanding the Afx Global Functions<br />Application Lifetime Control<br />Client Control Management<br />Connection Point Management<br />Control Registration<br />Exceptions<br />Initialization<br />Licensing<br />Type Information<br />Reviewing the OLE Macros<br />Class Factories<br />Client/Container Common Commands<br />Control Property Persistence<br />Dialog Data Exchange<br />Dispatch Maps<br />Event Maps<br />Property Page Data Mapping<br />Property Pages<br />Type Library Access<br />MFC and the OLE Class Categories<br />Active Document<br />Automation<br />Common Dialogs for OLE<br />Container<br />Control<br />Drag and Drop (Universal Data Transfer)<br />Document Servers<br />Support<br />Summary<br />MFC OLE Servers<br />Document Servers<br />Server Types<br />Full Server<br />Active Document<br />Container/Server<br />Mini-Server<br />Document Server Design<br />OLE Documents<br />Active Documents<br />Building an Active Document Server<br />Persistence<br />Rendering the View<br />Automation Servers<br />IDispatch<br />GetIDsOfNames<br />GetTypeInfo<br />GetTypeInfoCount<br />Invoke<br />IDispatch-Derived Interface in ODL<br />Calling Methods Through IDispatch<br />GetIDsOfNames<br />Type Information Methods<br />Invoke<br />Dispinterfaces Differ from Interfaces<br />Calling Methods Through IDispatch<br />Dual Interfaces<br />The Variant<br />An Automation Server Using MFC<br />Server Type<br />Declaring and Defining Additional Dispinterfaces<br />Adding Methods and Properties<br />Summary<br />MFC OLE Clients<br />IDispatch and Its Place in Automation<br />Interface Definition for Automation Servers<br />IDL and ATL<br />ODL and MFC<br />Dual Interfaces<br />MFC and Automation<br />Controller<br />Connecting to a Server<br />Server Review<br />Building a Controller<br />Using COleDispatchDriver<br />Using #import<br />Remote Automation<br />Summary<br />MFC ActiveX Controls<br />Development Strategy<br />MFC<br />ATL<br />MFC and ATL<br />Control Development<br />Two Faces of a Control<br />Runtime<br />Design Time<br />Subclassing a Control<br />MFC<br />ATL<br />Component Categories<br />ICatRegister<br />ICatInformation<br />Methods, Properties, and Events<br />Properties<br />Methods<br />Events<br />Property Pages<br />Property Pages in ATL<br />Property Pages in MFC<br />Component Registration<br />Registration Scripts<br />Registration and Controls<br />COM Object Subkeys<br />Building an MFC Control<br />Interface Definition<br />A Quick ATL Port<br />Summary<br />MFC ActiveX Control Containers<br />Active Document Container<br />Storage<br />Site Objects<br />In-Place Activation<br />Document Extensions<br />Building the Simplest Active Document Container<br />OLE Controls<br />Adding Containment to an Existing Project<br />ActiveX Container<br />Control Containment and Events<br />Summary<br />Using MFC and ATL<br />What Is ATL and Why Is It Important for Programming in MFC?<br />Helpful ATL COM Support for MFC Applications<br />COM Pointers the Smart Way<br />Other ATL COM Support<br />Advanced ATL Support for MFC Applications<br />Begin with Your MFC Application<br />Add the Required ATL Support<br />Summary<br />Scripting Your MFC Application<br />Scripting Basics<br />Scripting Interfaces<br />Dual Interfaces<br />Object Models<br />Implementing a Scripted Application<br />Object Implementation<br />Summary<br />MFC Database Programming<br />MFC Database Processing<br />Relational Database Concepts<br />Tables<br />Columns<br />Records<br />Cursors<br />Transactions<br />Storing and Retrieving Data<br />SELECT<br />INSERT<br />DELETE<br />UPDATE<br />Database Communication Mechanisms<br />ODBC<br />DAO<br />Which Methodology Should I Use?<br />ODBC/MFC<br />CDatabase<br />CRecordset<br />DAO<br />CDaoWorkspace<br />CDaoDatabase<br />CDaoRecordset<br />CDaoTableDef<br />CDaoQueryDef<br />Summary<br />Advanced Database Support<br />The COM Approach<br />OLE DB<br />ADO<br />Which One Should I Use?<br />OLE DB Consumers Using the ATL Wrapper Classes<br />CDataSource<br />CSession<br />Accessors<br />Rowsets<br />Accessing Datasource Data<br />Using the ADO C++ Interfaces<br />ADOConnection<br />ADORecordset<br />ADOCommand<br />ADOField<br />ADOProperty<br />ADOParameter<br />ADOError<br />Summary<br />MFC Utility Classes<br />Strings and Collections<br />Strings and String Classes<br />Inside the CString Class<br />Practical CString Usage<br />CString Summary<br />Collections<br />Inside Collection Classes<br />Templated Collections<br />The UNL_MultiEd Application<br />Overview<br />An STL Approach<br />Summary<br />File I/O and MFC<br />The CFile Class<br />Processing Files with CFile<br />Inside the CFile Class<br />The CStdioFile Class<br />The CMemFile Class<br />The CSharedFile Class<br />The CFileDialog Class<br />The User-Defined CFileDialog Class<br />Practical Usage of CFile and CFileDialog<br />Opening a File<br />Reading Data from a File<br />A Classical Approach<br />What Are Streams?<br />Summary<br />Exceptions<br />What Are They Good For?<br />Types of Exceptions<br />Structured Exception Handlers<br />Nesting of Structured Exception Handlers<br />Raising Structured Exceptions<br />Cleaning Up After an Exception<br />C++ Exceptions<br />Defining a C++ Exception Class<br />MFC Exceptions<br />MFC CException-Derived Classes<br />CMemoryException<br />CNotSupportedException<br />CArchiveException<br />CFileException<br />CResourceException<br />COleException<br />CDbException<br />COleDispatchException<br />CUserException<br />CDaoException<br />CInternetException<br />Deriving Your Own MFC-Compliant Exception Objects<br />Deleting Exceptions<br />Using MFC Exception Macros<br />Mixing Exceptions<br />Summary<br />MFC and the Web<br />MFC and DHTML<br />DHTML, MSIE, and the Internet<br />Using the Internet Explorer Web ActiveX Control<br />Internet Explorer ActiveX Control Basics<br />CHtmlView<br />CHtmlView and the Document/View Relationship<br />CHtmlView and COM<br />Using the Internet Explorer ActiveX Control in a Dialog Box<br />Using DHTML<br />The DHTML Object Model<br />The Document Object<br />Other DHTML Objects<br />Collection Objects<br />DHTML COM Interfaces<br />Obtaining the Document DHTML Interface<br />Obtaining the DHTML Collections Interfaces<br />Using the DHTML Interface<br />The DHTML Element Interface Methods<br />Document Navigation<br />Summary<br />CSocket Programming<br />How Do Network Communications Work?<br />Sockets, Ports, and Addresses<br />Winsock and MFC<br />Initializing the Winsock Environment<br />Creating a Socket<br />Making a Connection<br />Sending and Receiving Messages<br />Closing the Connection<br />Socket Events<br />Controlling Event Triggering<br />Detecting Errors<br />Getting Socket Information<br />Sockets and I/O Serialization<br />Building a Networked Application<br />Creating the Application Shell<br />Window Layout and Startup Functionality<br />Inheriting from the CAsyncSocket Class<br />Connecting the Application<br />Sending and Receiving<br />Ending the Connection<br />Summary<br />WinInet Programming<br />Web Application Protocols and WinInet<br />Hypertext Transfer Protocol<br />File Transfer Protocol<br />Gopher Protocol<br />WinInet API and MFC<br />Internet Session Basics<br />CInternetSession<br />CInternetFile<br />CInternetException<br />CInternetConnection<br />Building a Simple WinInet Application<br />Application-Level Functionality<br />HTTP Classes<br />FTP Classes<br />Gopher Classes<br />Building a Simple FTP Client<br />Summary<br />ISAPI Extensions<br />The Foundation<br />From There to Here<br />From GET to POST<br />Adding Some Form Elements<br />Change the Form<br />Change the Parse Map<br />Declare and Use the Handler Function<br />Add a Radio Button<br />Other Form Input Elements<br />Change the Form<br />Change the Parse Map<br />Change the Handler Function<br />Summary<br />MAPI and MFC<br />The Messaging Application Programming Interface<br />Client Applications<br />Two Higher-Level Alternatives: Simple MAPI and CMC<br />Simple MAPI<br />Common Messaging Calls<br />The MapiMessage Structure<br />The MapiFileDesc Structure<br />Limited MAPI Functionality in MFC<br />The CDocument Connection<br />Doing MAPI the MFC Way<br />The CDocument::OnFileSendMail() Method<br />Sample Program: MAPI1.EXE<br />Summary<br />TAPE and MFC<br />Overview<br />Assisted Telephony<br />Basic Telephony Service<br />Supplemental Telephony Service<br />Extended Telephony Service<br />History of TAPI<br />TAPI 1.3<br />TAPI 1.4<br />TAPI 1.5<br />TAPI 2<br />TAPI 2.1<br />TAPI 2.2<br />TAPI 3<br />Using Assisted Telephony<br />Using Basic Telephony<br />Configuring TAPI<br />Connecting with TAPI<br />Transmitting Data with TAPI<br />Disconnection with TAPI<br />Terminating a TAPI Session<br />Summary<br />MFC and Graphics Programming<br />MFC and OpenGL<br />What Is OpenGL?<br />Graphics Boot Camp<br />Core Terms and Key Concepts<br />The Basic Mathematics of Graphics Programming<br />OpenGL Boot Camp<br />OpenGL Datatypes<br />OpenGL Function Naming Conventions<br />OpenGL Render Function Scoping<br />The OpenGL Matrix Stack<br />The OpenGL Rendering Context<br />Minimal OpenGL Program and a Custom View<br />Creating Your Basic MFC Application<br />Adding the Custom OpenGL Base Class<br />Integrate the Custom View Class into Your Application<br />Build Your 3D Scene<br />Add the OpenGL Libraries to Your Project抯 Link List<br />2D and 3D Models<br />Basic Model Development<br />Model Transformations<br />Display Lists<br />Light<br />The Basics of Light in OpenGL<br />Types of Light<br />Object Material Properties<br />Texture Mapping<br />OpenGL Images and Windows Device-Independent Bitmaps<br />Applying Texture<br />Special Effects<br />Blending<br />Fog<br />Summary<br />MFC and DirectX<br />What Is DirectX?<br />DirectX in a Nutshell<br />DirectX Components<br />DirectX Basics<br />Differences in COM Programming Style and DirectX<br />DirectX Component Startup Sequence<br />DirectDraw Basics<br />Initializing DirectDraw<br />DirectDraw and Palettes<br />DirectDraw Surfaces<br />DirectDraw Page Flipping<br />DirectDraw from a Window<br />Using DirectDraw in Practice<br />Surfaces and Bitmaps<br />Windowed Rendering<br />Error Handling<br />DirectDraw Shutdown<br />Summary<br />Multimedia and MFC<br />Multimedia Fundamentals<br />The DirectX Media Player Control<br />Media Formats Supported by the Media Player Control<br />Inside the Media Player Control<br />The CMediaPlayer Class<br />Using the Media Player Control<br />Playing Sound<br />Working with Waves<br />Revisiting DirectSound<br />Using DirectSound to Play Sound Effects<br />Summary<br />Advanced MFC<br />Inside the Registry<br />Registry Usage<br />Configuration<br />Services Information<br />State<br />User Preferences<br />The Registry Structure<br />Programmatic Control of the Registry<br />The Registry API<br />The Registry Sample Application<br />The Registry Key Editor Dialog<br />Creating a New Key<br />Deleting a Key<br />Deleting a Name/Value Pair<br />A Word About Wrapping the Registry Functions<br />A Word About Installation<br />Summary<br />Writing and Using DLLs<br />Advantages of DLLs<br />Code Elimination<br />Modularity and Packaging<br />Extensibility<br />Inside an AFX DLL<br />Exporting Classes, Functions, and Data<br />The Big Deal About Exports<br />Mangled Names<br />Exporting Classes<br />What Goes Around, Comes Around<br />Exporting Explicit Functions<br />Exporting Data<br />Exporting MFC Data<br />Exporting the Destructor<br />Export Toolkit include Files<br />What to Export<br />Other DLL Issues<br />AfxLoadLibrary and AfxFreeLibrary<br />Designing for Extensibility and Reuse<br />Resource Location<br />Multiple Module Definition Files<br />Load Addresses and the Linker<br />Summary<br />Creating Custom Wizards<br />Property Sheets and Property Pages<br />The CPropertySheet and CPropertyPage Classes<br />The Wizard Walk and the Property Sheet Connection<br />Creating a Wizard<br />Setting the Wizard Mode<br />Enabling the Wizard Buttons<br />Displaying the Wizard<br />Wizard Notification Messages<br />Sample Program: Off to See the Wizard (WIZARD1.EXE)<br />Creating Wizard Page Dialog Template Resources<br />Create a Dialog Class for Each Dialog Resource<br />Exploring the Welcome Page: Class CIntroPage<br />Exploring the About You Page: Class CPage1<br />Updating Wizard Information for CPage2 and CPage3<br />Creating and Displaying the Wizard<br />Summary<br />Index