1181
Table of Contents 1 Introduction ...................................................................................................................................................................................... 4 Foreword ...................................................................................................................................................................................... 6 About the Author ........................................................................................................................................................................ 10 Core MFC ...................................................................................................................................................................................... 10 The MFC Architecture ........................................................................................................................................................... 10 A Brief History of MFC ...................................................................................................................................................... 10 The MFC Class Hierarchy ................................................................................................................................................ 10 CObject ........................................................................................................................................................................ 10 CCmdTarget ................................................................................................................................................................. 10 CWinThread ................................................................................................................................................................. 10 CWinApp ...................................................................................................................................................................... 10 CWnd ........................................................................................................................................................................... 10 CFrameWnd ................................................................................................................................................................. 10 CView ........................................................................................................................................................................... 10 CDocument .................................................................................................................................................................. 10 Summary ............................................................................................................................................................................ 36 MFC Dialogs, Controls, and Data Interaction ................................................................................................................ 36 Creating an Application ..................................................................................................................................................... 36 Starting and Using MFC AppWizard ............................................................................................................................. 36 The AppWizard-Generated Code .................................................................................................................................. 36 Modifying the Application .................................................................................................................................................. 36 Adding Dialog Controls ................................................................................................................................................. 36 Adding Initialization ....................................................................................................................................................... 36 Using Dialog Controls ................................................................................................................................................... 36 ToolTips ............................................................................................................................................................................... 36 Enabling ToolTips ......................................................................................................................................................... 36 Displaying Text ............................................................................................................................................................. 36 Dialog Data Exchange ...................................................................................................................................................... 36 Standard DDX .............................................................................................................................................................. 36 UpdateData .................................................................................................................................................................. 36 Using Standard Dialog Boxes .......................................................................................................................................... 36 File Open/Save ............................................................................................................................................................. 36 Color Selector ............................................................................................................................................................... 36 Font Selector ................................................................................................................................................................ 36 Print Dialog ................................................................................................................................................................... 36 Summary ............................................................................................................................................................................ 60 The Windows Common Controls ....................................................................................................................................... 60 Initializing and Using the Common Controls ................................................................................................................. 60 Notifications for Windows Common Controls ................................................................................................................ 60 The Notification Message Structure .............................................................................................................................. 60 Overview of the Notification Process ............................................................................................................................ 60 A Better Notification Handling Scheme ......................................................................................................................... 60 Specifying Notification Ranges with ON_NOTIFY_RANGE ......................................................................................... 60 Hot Key Controls: Class CHotKeyCtrl ............................................................................................................................ 60 CHotKeyCtrl Class Methods ......................................................................................................................................... 60 Creating and Initializing a CHotKeyCtrl Object ............................................................................................................. 60 Using a Hot Key Control ............................................................................................................................................... 60 Spin Controls: Class CSpinButtonCtrl ............................................................................................................................ 60 Spin Control Styles ....................................................................................................................................................... 60 CSpinButtonCtrl Messages ...........................................................................................................................................

MFC Programming With Visual C++ 6 Unleashed 1999

Embed Size (px)

DESCRIPTION

old mfc book but still good for advanced mfc programer

Citation preview

  • Table of Contents

    1Introduction ......................................................................................................................................................................................4Foreword ......................................................................................................................................................................................6About the Author ........................................................................................................................................................................

    10Core MFC ......................................................................................................................................................................................10The MFC Architecture ...........................................................................................................................................................10A Brief History of MFC ......................................................................................................................................................10The MFC Class Hierarchy ................................................................................................................................................10CObject ........................................................................................................................................................................10CCmdTarget .................................................................................................................................................................10CWinThread .................................................................................................................................................................10CWinApp ......................................................................................................................................................................10CWnd ...........................................................................................................................................................................10CFrameWnd .................................................................................................................................................................10CView ...........................................................................................................................................................................10CDocument ..................................................................................................................................................................10Summary ............................................................................................................................................................................36MFC Dialogs, Controls, and Data Interaction ................................................................................................................36Creating an Application .....................................................................................................................................................36Starting and Using MFC AppWizard .............................................................................................................................36The AppWizard-Generated Code ..................................................................................................................................36Modifying the Application ..................................................................................................................................................36Adding Dialog Controls .................................................................................................................................................36Adding Initialization .......................................................................................................................................................36Using Dialog Controls ...................................................................................................................................................36ToolTips ...............................................................................................................................................................................36Enabling ToolTips .........................................................................................................................................................36Displaying Text .............................................................................................................................................................36Dialog Data Exchange ......................................................................................................................................................36Standard DDX ..............................................................................................................................................................36UpdateData ..................................................................................................................................................................36Using Standard Dialog Boxes ..........................................................................................................................................36File Open/Save .............................................................................................................................................................36Color Selector ...............................................................................................................................................................36Font Selector ................................................................................................................................................................36Print Dialog ...................................................................................................................................................................36Summary ............................................................................................................................................................................60The Windows Common Controls .......................................................................................................................................60Initializing and Using the Common Controls .................................................................................................................60Notifications for Windows Common Controls ................................................................................................................60The Notification Message Structure ..............................................................................................................................60Overview of the Notification Process ............................................................................................................................60A Better Notification Handling Scheme .........................................................................................................................60Specifying Notification Ranges with ON_NOTIFY_RANGE .........................................................................................60Hot Key Controls: Class CHotKeyCtrl ............................................................................................................................60CHotKeyCtrl Class Methods .........................................................................................................................................60Creating and Initializing a CHotKeyCtrl Object .............................................................................................................60Using a Hot Key Control ...............................................................................................................................................60Spin Controls: Class CSpinButtonCtrl ............................................................................................................................60Spin Control Styles .......................................................................................................................................................60CSpinButtonCtrl Messages ...........................................................................................................................................

  • 60CSpinButtonCtrl Class Methods ...................................................................................................................................60Creating and Initializing a Spin Control .........................................................................................................................60Sample Program: SPIN1 ..............................................................................................................................................60Slider Controls: Class CSliderCtrl ...................................................................................................................................60Slider Control Styles .....................................................................................................................................................60CSliderCtrl Messages ...................................................................................................................................................60CSliderCtrl Class Methods ............................................................................................................................................60Creating and Initializing a Slider Control .......................................................................................................................60Sample Program: Slider Controls (SLIDER1) ...............................................................................................................60Sample Program: SLIDER1 ..........................................................................................................................................60Progress Bar Controls: Class CProgressCtrl ................................................................................................................60CProgressCtrl Class Methods ......................................................................................................................................60Creating and Initializing a CProgressCtrl Object ..........................................................................................................60Using a Progress Control ..............................................................................................................................................60Image Lists: Class CImageList ........................................................................................................................................60CImageList Class Methods ...........................................................................................................................................60Creating and Initializing a CImageList Control .............................................................................................................60List View Controls: Class CListCtrl .................................................................................................................................60List View Control Styles ................................................................................................................................................60Image Lists and the List View Control ...........................................................................................................................60List View Items and Subitems .........................................................................................................................................60List View Notification Messages ...................................................................................................................................60Creating and Initializing a CListCtrl Object ...................................................................................................................60Using the List View Control ...........................................................................................................................................60Tree View Controls: Class CTreeCtrl ..............................................................................................................................60Tree View Control Styles ..............................................................................................................................................60Tree View Notification Messages ..................................................................................................................................60CTreeCtrl Class Methods .............................................................................................................................................60Creating and Initializing a Tree View Control ...............................................................................................................60Using a CTreeCtrl Object ..............................................................................................................................................60Sample Program: TREELIST.EXE ................................................................................................................................60Tab Controls: Class CTabCtrl ...........................................................................................................................................60Tab Control Styles ........................................................................................................................................................60Tab Control Notification Messages ...............................................................................................................................60CTabCtrl Class Methods ...............................................................................................................................................60The Tab Item Structure (TC_ITEM) ...............................................................................................................................60Creating and Initializing a Tab Control ..........................................................................................................................60Using a Tab Control ......................................................................................................................................................60Animate Controls: Class CAnimateCtrl ..........................................................................................................................60Animate Control Styles .................................................................................................................................................60Animate Control Notification Messages ........................................................................................................................60CAnimateCtrl Class Methods ........................................................................................................................................60Creating and Initializing an Animate Control ................................................................................................................60Using an Animate Control .............................................................................................................................................60Rich Edit Controls: Class CRichEditCtrl .........................................................................................................................60Rich Edit Control Window Styles ..................................................................................................................................60The Character Format Structure (CHARFORMAT) .......................................................................................................60The Paragraph Format Structure (PARAFORMAT) .......................................................................................................60CRichEditCtrl Class Methods .......................................................................................................................................60CRichEditCtrl Line-Related Methods ............................................................................................................................60CRichEditCtrl Text-Selection Methods ..........................................................................................................................60CRichEditCtrl Formatting Methods ...............................................................................................................................60CRichEditCtrl Editing Methods .....................................................................................................................................60CRichEditCtrl Clipboard Methods .................................................................................................................................

  • 60CRichEditCtrl General-Purpose Methods ......................................................................................................................60Creating and Initializing a Rich Edit Control .................................................................................................................60Using a Rich Edit Control .............................................................................................................................................60Summary ............................................................................................................................................................................

    118Painting, Device Contexts, Bitmaps, and Fonts .........................................................................................................118Device Contexts ..............................................................................................................................................................118The Graphics Device Interface .....................................................................................................................................118MFC Wrapping ...........................................................................................................................................................118MFC Device Context Classes .......................................................................................................................................118The Base Class: CDC ................................................................................................................................................118Painting with Class CPaintDC ....................................................................................................................................118Managing Client Areas with Class CClientDC ............................................................................................................118Managing Frame Windows with Class CWindowDC ..................................................................................................118Windows Graphic Objects .............................................................................................................................................118Pens: Class CPen ......................................................................................................................................................118Brushes: Class CBrush ..............................................................................................................................................118Fonts: Class CFont ....................................................................................................................................................118Bitmaps: Class CBitmap ............................................................................................................................................118Palettes: Class CPalette ............................................................................................................................................118Regions: Class CRgn .................................................................................................................................................118GDI Coordinate Systems ...............................................................................................................................................118Logical Mapping Modes .............................................................................................................................................118Vector Graphics ...............................................................................................................................................................118Drawing Modes ..........................................................................................................................................................118Lines and Polylines ....................................................................................................................................................118Rectangles .................................................................................................................................................................118Regions .....................................................................................................................................................................118Polygons ....................................................................................................................................................................118Ellipses ......................................................................................................................................................................118Bezier Curves ............................................................................................................................................................118Fonts and Text .................................................................................................................................................................118Font Characteristics ...................................................................................................................................................118The TEXTMETRIC Structure ......................................................................................................................................118The LOGFONT Structure ...........................................................................................................................................118Font Creation .............................................................................................................................................................118Drawing Text ..............................................................................................................................................................118Sample Program: Vector Graphics and Text Methods (VECTEXT1.EXE) ............................................................118Raster Graphics ..............................................................................................................................................................118Named Raster Operations (ROPs) .............................................................................................................................118Bitmaps .....................................................................................................................................................................118Device-Dependent Bitmaps .......................................................................................................................................118Device-Independent Bitmaps (DIBs) ..........................................................................................................................118The CBitmap Class ....................................................................................................................................................118Transferring and Contorting Bitmaps ..........................................................................................................................118Bitmap Resources ..........................................................................................................................................................118Tacking Resources onto an Executable File ..............................................................................................................118Getting Image Resources out of an Executable File .................................................................................................118Sample Program: Exploring Bitmap Resources (BITMAP1) ...................................................................................118Summary ..........................................................................................................................................................................173Custom Control Development ..........................................................................................................................................173Window Classes Versus C++ Classes ........................................................................................................................173A Validating Edit Control ................................................................................................................................................173The Clock Static Control ................................................................................................................................................173Control Metrics ..........................................................................................................................................................

  • 173Painting the Face ......................................................................................................................................................173Locating the Hands ....................................................................................................................................................173Painting the Hands ....................................................................................................................................................173Setting the Time ........................................................................................................................................................173Pitfalls of Subclassing Standard Controls ..................................................................................................................173The Hyperlink Control ....................................................................................................................................................173Implementation Strategy ............................................................................................................................................173Font Processing ........................................................................................................................................................173Painting the Window ..................................................................................................................................................173Controlling the Cursor ................................................................................................................................................173Mouse Input ...............................................................................................................................................................173Keyboard Input ..........................................................................................................................................................173Launching the Link ....................................................................................................................................................173Advanced Custom Control Topics ................................................................................................................................173Subclassing Limitations .............................................................................................................................................173Notifications ...............................................................................................................................................................173Using the Resource Editor with Custom Classes ......................................................................................................173Summary ..........................................................................................................................................................................195The MFC Application Object, Message Routing, and Idle Processing ..............................................................195The MFC Application Object .........................................................................................................................................195CWinApp and Application Lifetime .............................................................................................................................195The CWinApp Data Members ....................................................................................................................................195The CWinApp Member Functions ..............................................................................................................................195Application-Specific Initialization ................................................................................................................................195Functionality in InitInstance .......................................................................................................................................195OLE Container Support .............................................................................................................................................1953D Look for Windows NT 3.5x ...................................................................................................................................195Registry Usage ..........................................................................................................................................................195Most Recently Used Files List ...................................................................................................................................195SDI and MDI Document/View ....................................................................................................................................195Main Frame Window Creation ...................................................................................................................................195Automation Support ...................................................................................................................................................195Rich Edit Control Support ..........................................................................................................................................195Command-Line Handling ...........................................................................................................................................195Message Routing, Message Maps, and Message Categories ...............................................................................195Message Routing .......................................................................................................................................................195PreTranslateMessage ................................................................................................................................................195Message Maps ..........................................................................................................................................................195Idle Processing ...............................................................................................................................................................195OnIdle ........................................................................................................................................................................195Idle Processing for Dialogs ........................................................................................................................................195The Splash Screen Component ...................................................................................................................................195Summary ..........................................................................................................................................................................218Documents, Views, and Applications That Use Them .................................................................................218The Document/View Architecture ...................................................................................................................................218Documents, Frames, and Views ..................................................................................................................................218Document Templates .................................................................................................................................................218Creating New Documents .............................................................................................................................................218Opening New Files ....................................................................................................................................................218Single Versus Multiple Document Templates .............................................................................................................218Views ................................................................................................................................................................................218The CView Class .......................................................................................................................................................218The CScrollView Class ..............................................................................................................................................218The CFormView Class ...............................................................................................................................................

  • 218The Database View Classes ......................................................................................................................................218The Control Views .....................................................................................................................................................218Changing Views in an SDI .........................................................................................................................................218Using the MDI ............................................................................................................................................................218Summary ..........................................................................................................................................................................237Extending the User Interface ............................................................................................................................................237Responding to the User .................................................................................................................................................237Keyboard Messaging .................................................................................................................................................237Handling Keyboard Messages ...................................................................................................................................237Mouse Messaging .....................................................................................................................................................237Handling Mouse Messages ........................................................................................................................................237User Interfaces and AppWizard ...................................................................................................................................237Extending Menus ............................................................................................................................................................237Obtaining Menus and Pop-up Menus .........................................................................................................................237Adding Menu Items ....................................................................................................................................................237Using Floating Pop-up Menus ....................................................................................................................................237Putting Control Bars to Use ..........................................................................................................................................237Using Toolbars and Rebars ........................................................................................................................................237Using Status Bars ......................................................................................................................................................237Showing and Hiding Control Bars ..............................................................................................................................237Supporting ToolTips ...................................................................................................................................................237Updating the User Interface ..........................................................................................................................................237Property Sheets and Wizards .......................................................................................................................................237MFC's Support for Property Sheets and Wizards ......................................................................................................237Creating a Simple Wizard ..........................................................................................................................................237Splitting a View ...............................................................................................................................................................237Summary ..........................................................................................................................................................................271Printing ....................................................................................................................................................................................271Printing Fundamentals ...................................................................................................................................................271Printing with MFC ...........................................................................................................................................................271Printing in the View ....................................................................................................................................................271The PrintInfo Object ...................................................................................................................................................271Printing Menu Commands .........................................................................................................................................271Printing and GDI Mapping Modes ................................................................................................................................271WYSIWYG Printing ........................................................................................................................................................271Application Resources ...............................................................................................................................................271The Application Class ................................................................................................................................................271The View Class ..........................................................................................................................................................271Pagination ........................................................................................................................................................................271Printing with a Known Page Count .............................................................................................................................271Printing with an Unknown Page Count .......................................................................................................................271Printing Page Numbers .............................................................................................................................................271Stopping and Aborting Print Jobs .................................................................................................................................271Halting a Print Job in OnPrepareDC() ........................................................................................................................271Halting a Print Job in OnPrint() ..................................................................................................................................271Summary ..........................................................................................................................................................................291MFC and COM Programming .......................................................................................................................................291COM .........................................................................................................................................................................................291A Little History .................................................................................................................................................................291Interfaces, Objects, and Methods ................................................................................................................................291Some Terminology .....................................................................................................................................................291A Real-World View .....................................................................................................................................................291The IUnknown Interface .............................................................................................................................................291Servers, Clients, and Classes ......................................................................................................................................

  • 291The COM Runtime Environment ..................................................................................................................................291Defining the Class Factory .........................................................................................................................................291How Are COM Objects Reused? ................................................................................................................................291Marshaling and Threading ............................................................................................................................................291Marshaling .................................................................................................................................................................291Threading ..................................................................................................................................................................291COM, OLE, and Automation .........................................................................................................................................291IDispatch ...................................................................................................................................................................291Automation Servers, Objects, and Controllers ...........................................................................................................291Supporting Both IDispatch and IUnknown ..................................................................................................................291Persisting COM Data .....................................................................................................................................................291Structured Storage ....................................................................................................................................................291Identifying COM Data (Monikers) .................................................................................................................................291Transferring Data ............................................................................................................................................................291Uniform Data Transfer ...............................................................................................................................................291Connectable Objects .................................................................................................................................................291DCOM ...............................................................................................................................................................................291Object Creation .........................................................................................................................................................291Invoking Methods ......................................................................................................................................................291Security Issues ..........................................................................................................................................................291Some Important Information .........................................................................................................................................291BSTR .........................................................................................................................................................................291SAFEARRAY .............................................................................................................................................................291HRESULT ..................................................................................................................................................................291VARIANT ...................................................................................................................................................................291Further Reading ..............................................................................................................................................................291Summary ..........................................................................................................................................................................316COM and MFC ......................................................................................................................................................................316Understanding the Afx Global Functions .....................................................................................................................316Application Lifetime Control .......................................................................................................................................316Client Control Management .......................................................................................................................................316Connection Point Management ..................................................................................................................................316Control Registration ...................................................................................................................................................316Exceptions .................................................................................................................................................................316Initialization ................................................................................................................................................................316Licensing ...................................................................................................................................................................316Type Information ........................................................................................................................................................316Reviewing the OLE Macros ...........................................................................................................................................316Class Factories ..........................................................................................................................................................316Client/Container Common Commands ......................................................................................................................316Control Property Persistence .....................................................................................................................................316Dialog Data Exchange ...............................................................................................................................................316Dispatch Maps ...........................................................................................................................................................316Event Maps ...............................................................................................................................................................316Property Page Data Mapping .....................................................................................................................................316Property Pages ..........................................................................................................................................................316Type Library Access ..................................................................................................................................................316MFC and the OLE Class Categories ...........................................................................................................................316Active Document .......................................................................................................................................................316Automation ................................................................................................................................................................316Common Dialogs for OLE ..........................................................................................................................................316Container ...................................................................................................................................................................316Control .......................................................................................................................................................................316Drag and Drop (Universal Data Transfer) ...................................................................................................................

  • 316Document Servers .....................................................................................................................................................316Support ......................................................................................................................................................................316Summary ..........................................................................................................................................................................348MFC OLE Servers ...............................................................................................................................................................348Document Servers ..........................................................................................................................................................348Server Types ...................................................................................................................................................................348Full Server .................................................................................................................................................................348Active Document .......................................................................................................................................................348Container/Server .......................................................................................................................................................348Mini-Server ................................................................................................................................................................348Document Server Design ..............................................................................................................................................348OLE Documents ........................................................................................................................................................348Active Documents .....................................................................................................................................................348Building an Active Document Server ...........................................................................................................................348Persistence ...............................................................................................................................................................348Rendering the View ...................................................................................................................................................348Automation Servers ........................................................................................................................................................348IDispatch ..........................................................................................................................................................................348GetIDsOfNames ........................................................................................................................................................348GetTypeInfo ...............................................................................................................................................................348GetTypeInfoCount .....................................................................................................................................................348Invoke ........................................................................................................................................................................348IDispatch-Derived Interface in ODL .............................................................................................................................348Calling Methods Through IDispatch .............................................................................................................................348GetIDsOfNames ........................................................................................................................................................348Type Information Methods .........................................................................................................................................348Invoke ........................................................................................................................................................................348Dispinterfaces Differ from Interfaces ...........................................................................................................................348Calling Methods Through IDispatch .............................................................................................................................348Dual Interfaces ................................................................................................................................................................348The Variant ......................................................................................................................................................................348An Automation Server Using MFC ...............................................................................................................................348Server Type ...............................................................................................................................................................348Declaring and Defining Additional Dispinterfaces .......................................................................................................348Adding Methods and Properties .................................................................................................................................348Summary ..........................................................................................................................................................................369MFC OLE Clients .................................................................................................................................................................369IDispatch and Its Place in Automation .........................................................................................................................369Interface Definition for Automation Servers ................................................................................................................369IDL and ATL ...............................................................................................................................................................369ODL and MFC ...........................................................................................................................................................369Dual Interfaces ..........................................................................................................................................................369MFC and Automation .....................................................................................................................................................369Controller ...................................................................................................................................................................369Connecting to a Server ..............................................................................................................................................369Server Review ...........................................................................................................................................................369Building a Controller .......................................................................................................................................................369Using COleDispatchDriver .........................................................................................................................................369Using #import ............................................................................................................................................................369Remote Automation ...................................................................................................................................................369Summary ..........................................................................................................................................................................395MFC ActiveX Controls ........................................................................................................................................................395Development Strategy ...................................................................................................................................................395MFC ..........................................................................................................................................................................

  • 395ATL ............................................................................................................................................................................395MFC and ATL .............................................................................................................................................................395Control Development .....................................................................................................................................................395Two Faces of a Control ..................................................................................................................................................395Runtime .....................................................................................................................................................................395Design Time ..............................................................................................................................................................395Subclassing a Control ....................................................................................................................................................395MFC ..........................................................................................................................................................................395ATL ............................................................................................................................................................................395Component Categories ..................................................................................................................................................395ICatRegister ..............................................................................................................................................................395ICatInformation ..........................................................................................................................................................395Methods, Properties, and Events .................................................................................................................................395Properties ..................................................................................................................................................................395Methods ....................................................................................................................................................................395Events .......................................................................................................................................................................395Property Pages ...............................................................................................................................................................395Property Pages in ATL ...............................................................................................................................................395Property Pages in MFC .............................................................................................................................................395Component Registration ................................................................................................................................................395Registration Scripts ...................................................................................................................................................395Registration and Controls ..........................................................................................................................................395COM Object Subkeys ....................................................................................................................................................395Building an MFC Control ...............................................................................................................................................395Interface Definition .........................................................................................................................................................395A Quick ATL Port .............................................................................................................................................................395Summary ..........................................................................................................................................................................429MFC ActiveX Control Containers ....................................................................................................................................429Active Document Container ..........................................................................................................................................429Storage ......................................................................................................................................................................429Site Objects ...............................................................................................................................................................429In-Place Activation .....................................................................................................................................................429Document Extensions ................................................................................................................................................429Building the Simplest Active Document Container ....................................................................................................429OLE Controls ...................................................................................................................................................................429Adding Containment to an Existing Project ................................................................................................................429ActiveX Container ......................................................................................................................................................429Control Containment and Events ...............................................................................................................................429Summary ..........................................................................................................................................................................454Using MFC and ATL ............................................................................................................................................................454What Is ATL and Why Is It Important for Programming in MFC? ...........................................................................454Helpful ATL COM Support for MFC Applications ........................................................................................................454COM Pointers the Smart Way ...................................................................................................................................454Other ATL COM Support ............................................................................................................................................454Advanced ATL Support for MFC Applications .............................................................................................................454Begin with Your MFC Application ...............................................................................................................................454Add the Required ATL Support ..................................................................................................................................454Summary ..........................................................................................................................................................................481Scripting Your MFC Application .......................................................................................................................................481Scripting Basics ..............................................................................................................................................................481Scripting Interfaces ....................................................................................................................................................481Dual Interfaces ..........................................................................................................................................................481Object Models .................................................................................................................................................................481Implementing a Scripted Application ...........................................................................................................................

  • 481Object Implementation ...............................................................................................................................................481Summary ..........................................................................................................................................................................503MFC Database Programming .......................................................................................................................................503MFC Database Processing ...............................................................................................................................................503Relational Database Concepts .....................................................................................................................................503Tables ........................................................................................................................................................................503Columns ....................................................................................................................................................................503Records .....................................................................................................................................................................503Cursors ......................................................................................................................................................................503Transactions ..............................................................................................................................................................503Storing and Retrieving Data ..........................................................................................................................................503SELECT ....................................................................................................................................................................503INSERT .....................................................................................................................................................................503DELETE ....................................................................................................................................................................503UPDATE ....................................................................................................................................................................503Database Communication Mechanisms .....................................................................................................................503ODBC ........................................................................................................................................................................503DAO ..........................................................................................................................................................................503Which Methodology Should I Use? ............................................................................................................................503ODBC/MFC ......................................................................................................................................................................503CDatabase ................................................................................................................................................................503CRecordset ...............................................................................................................................................................503DAO ..................................................................................................................................................................................503CDaoWorkspace .......................................................................................................................................................503CDaoDatabase ..........................................................................................................................................................503CDaoRecordset .........................................................................................................................................................503CDaoTableDef ...........................................................................................................................................................503CDaoQueryDef ..........................................................................................................................................................503Summary ..........................................................................................................................................................................528Advanced Database Support ...........................................................................................................................................528The COM Approach ........................................................................................................................................................528OLE DB .....................................................................................................................................................................528ADO ..........................................................................................................................................................................528Which One Should I Use? .........................................................................................................................................528OLE DB Consumers Using the ATL Wrapper Classes .............................................................................................528CDataSource .............................................................................................................................................................528CSession ...................................................................................................................................................................528Accessors ..................................................................................................................................................................528Rowsets ....................................................................................................................................................................528Accessing Datasource Data ......................................................................................................................................528Using the ADO C++ Interfaces .....................................................................................................................................528ADOConnection .........................................................................................................................................................528ADORecordset ..........................................................................................................................................................528ADOCommand ..........................................................................................................................................................528ADOField ...................................................................................................................................................................528ADOProperty .............................................................................................................................................................528ADOParameter ..........................................................................................................................................................528ADOError ...................................................................................................................................................................528Summary ..........................................................................................................................................................................543MFC Utility Classes ..............................................................................................................................................................543Strings and Collections ......................................................................................................................................................543Strings and String Classes ............................................................................................................................................543Inside the CString Class ............................................................................................................................................543Practical CString Usage ............................................................................................................................................

  • 543CString Summary ......................................................................................................................................................543Collections .......................................................................................................................................................................543Inside Collection Classes ..........................................................................................................................................543Templated Collections ...............................................................................................................................................543The UNL_MultiEd Application .......................................................................................................................................543Overview ...................................................................................................................................................................543An STL Approach ............................................................................................................................................................543Summary ..........................................................................................................................................................................563File I/O and MFC ..................................................................................................................................................................563The CFile Class ..............................................................................................................................................................563Processing Files with CFile ........................................................................................................................................563Inside the CFile Class ....................................................................................................................................................563The CStdioFile Class .................................................................................................................................................563The CMemFile Class .................................................................................................................................................563The CSharedFile Class ..............................................................................................................................................563The CFileDialog Class ...................................................................................................................................................563The User-Defined CFileDialog Class ...........................................................................................................................563Practical Usage of CFile and CFileDialog ..................................................................................................................563Opening a File ...........................................................................................................................................................563Reading Data from a File ...........................................................................................................................................563A Classical Approach .....................................................................................................................................................563What Are Streams? ...................................................................................................................................................563Summary ..........................................................................................................................................................................581Exceptions ..............................................................................................................................................................................581What Are They Good For? ............................................................................................................................................581Types of Exceptions .......................................................................................................................................................581Structured Exception Handlers .....................................................................................................................................581Nesting of Structured Exception Handlers ..................................................................................................................581Raising Structured Exceptions .....................................................................................................................................581Cleaning Up After an Exception ...................................................................................................................................581C++ Exceptions ...............................................................................................................................................................581Defining a C++ Exception Class ..................................................................................................................................581MFC Exceptions ..............................................................................................................................................................581MFC CException-Derived Classes .............................................................................................................................581CMemoryException ...................................................................................................................................................581CNotSupportedException ..........................................................................................................................................581CArchiveException ....................................................................................................................................................581CFileException ..........................................................................................................................................................581CResourceException .................................................................................................................................................581COleException ...........................................................................................................................................................581CDb