cover Copyright© 1999 by Microsoft Corporation PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 1999 by Microsoft Corporation All rights reserved No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher Library of Congress Cataloging-in-Publication Data Desktop Applications with Microsoft Visual C++ 6.0 : MCSD Training Kit / Microsoft Corporation p cm Includes index ISBN 0-7356-0795-8 Electronic data processing personnel Certification Microsoft software Examinations Study guides C++ (Computer program language) Microsoft Visual C++ I Microsoft Corporation QA76.3.D47 1999 005.26'8-dc21 99-33877 Printed and bound in the United States of America 1 2 3 4 5 6 7 8 9 QMQM 4 3 2 1 0 9 Distributed in Canada by Penguin Books Canada Limited A CIP catalogue record for this book is available from the British Library Microsoft Press books are available through booksellers and distributors worldwide For further information about international editions, contact your local Microsoft Corporation office or contact Microsoft Press International directly at fax (425) 936-7329 Visit our Web site at mspress.microsoft.com NT is a trademark of Northern Telecom Limited ActiveX, Developer Studio, FoxPro, IntelliSense, JScript, Microsoft, Microsoft Press, MSDN, MS-DOS, Natural, SourceSafe, Visual Basic, Visual C++, Visual InterDev, Visual J++, Visual SourceSafe, Visual Studio, Win32, Windows, Windows NT, and Wingdings are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries Other product and company names mentioned herein may be the trademarks of their respective owners The example companies, organizations, products, people, and events depicted herein are fictitious No association with any real company, organization, product, person, or event is intended or should be inferred Acquisitions Editor: Eric Stroo Project Editor: Victoria Thulman About This Book Welcome to Desktop Applications with Microsoft Visual C++ 6.0 MCSD Training Kit By completing the chapters and associated Lab exercises in this course, you will acquire the knowledge and skills necessary to develop solutions using Visual C++ 6.0 This book addresses the objectives of the Microsoft Certified Solution Developer (MCSD) Exam 70-016, "Designing and Implementing Desktop Applications with Microsoft Visual C++ 6.0." This book provides content that supports the skills measured by the 70-016 exam Review questions at the end of each chapter test your knowledge of the chapter material, and help you prepare for the exam NOTE For more information on becoming a Microsoft Certified Solution Developer, see "Microsoft Certified Professional Program" later in this section Intended Audience This course is designed for individuals interested in developing their skills in Microsoft Visual C++ 6.0 while developing desktop applications Topics include using the Microsoft Solutions Framework (MSF); building applications with the Microsoft Foundation Classes (MFC); creating user interfaces; implementing application behaviors; and working with persistent data Also included are adding database support to applications; creating Component Object Model (COM) components and ActiveX controls; using MFC and the Active Template Library (ATL); Internet programming; error handling, debugging, and testing; and application deployment Prerequisites This book assumes that you have a good working knowledge of C++ application development and are acquainted with but not knowledgeable about Microsoft Visual C++ 6.0 and the Microsoft Windows Application Programming Interface (API) Before beginning this self-paced course, you should have: A thorough working knowledge of the C++ language as described by the ANSI standard, including language features such as templates and exception handling A good understanding of the principles of object-oriented software development A good basic understanding of the operation of a Windows application, and the features of the Windows user interface Course Overview This course combines text, graphics, and review questions to teach you about designing and implementing desktop applications with Visual C++ 6.0 The course assumes that you will work through the book from beginning to end However, you can choose a customized track and complete only the sections that interest you If you choose to customize your course, see the "Before You Begin" section in each chapter for important information regarding prerequisites The book is divided into the following chapters: Chapter 1, Preparing for Application Development In this chapter, you will learn about the elements of designing a Visual C++ application using MSF design concepts You will study the issues that you should consider in planning your design You will also be given an overview of the Visual C++ development tools through a description of the installation options Chapter 2, Visual C++ Development Environment This chapter discusses the development environment and the tools that enable you to create applications using Visual C++ You will use the MFC AppWizard to generate a development project, which contains source code and resource files that you can compile into a working executable program You will explore features of the Visual C++ development environment and learn how to configure options for your project You will also learn how to use Microsoft Visual SourceSafe to manage source code control for a software development team Chapter 3, Building Applications with the Microsoft Foundation Classes In this chapter, you will learn about specific MFC classes and their role in Windows application development You will learn how the MFC framework implements the basic components of a Windows application, and how it provides an architecture that enables the processing, display, and storage of the application's data Chapter 4, Creating the User Interface This chapter explores some of the elements of a typical Windows application user interface You will edit application menus and toolbars, and add code to handle user selections You will update the interface to communicate information to the user You will also learn how dialog boxes are used in an application, and you will use the dialog editor to create a dialog box template Chapter 5, Implementing Application Behaviors This chapter discusses some of the MFC programming techniques that you can use to implement the operational behavior of an application You will learn how to make use of dialog box classes, and also how to take advantage of the multithreading capabilities of the Win32 platform You will learn more about the techniques used to display application data to an on-screen window or a printer You will also implement Help for an MFC application Chapter 6, Persistent Data In this chapter, you will learn ways to make your application data and settings persistent You will use the MFC CFile class for general file input/output (I/O) operations You will also use the serialization facilities of the MFC framework to save and restore structured application data Finally, you will save individual data items, such as application settings, in the system registry Chapter 7, Adding Database Support In this chapter, you will learn about a variety of data access interfaces available to Visual C++ application developers These interfaces include features of MFC that provide support for data access and ActiveX Data Objects (ADO), Microsoft's standard interface to essentially all forms of external data Chapter 8, Introducing the Component Object Model This chapter provides a conceptual introduction to COM COM is a binary standard that defines a way for software objects, developed in different languages or operating on different platforms, to communicate with each other and with other applications Also included in this introduction are ActiveX controls ActiveX controls are COM components designed for placement in an ActiveX control container, such as an application dialog box or a Web page, to perform a self-contained function Chapter 9, Creating COM Components In this chapter, you will create a simple COM component using the ActiveX Template Library (ATL) You will review aspects of the source code generated for your COM object by the ATL wizards, and learn about other approaches to generating COM components Chapter 10, COM Clients This chapter explains how applications and components can act as clients of COM server components by making use of the services that the component provides You will learn how the Visual C++ compiler simplifies the creation of COM client code You will also learntechniques for creating COM objects that contain instances of other COM objects Chapter 11, Creating ActiveX Controls In this chapter, you will create a simple ActiveX control using MFC, and analyze the MFC-generated code You will then develop the same control using the ActiveX Template Library (ATL) You will thus be able to compare the two development methods and assess which method might be most appropriate in a particular development scenario Chapter 12, Internet Programming This chapter introduces some of the features of Visual C++ 6.0 that allow you to create Internet-based applications You will learn how you can use Dynamic HTML to create application user interfaces, and how you can add Web-browsing capabilities to your applications and components You will study how to develop an application that creates ActiveX documents—documents that can be hosted by Microsoft Internet Explorer for viewing and editing over the Web You will also learn how to create Internet Server API (ISAPI) DLLs that enhance the services provided by Microsoft Web servers Chapter 13, Error Handling, Debugging, and Testing In this chapter, you will learn about the three steps that make up the second half of the software development process: error handling, debugging, and testing These final steps are an essential part of the development process, and merit at least as much attention as that given to the designing and coding phases Chapter 14, Deploying Desktop Applications In this chapter, you will learn some of the ways a Windows application created with Visual C++ can be efficiently deployed After presenting an overview of deployment methods, the chapter shows how to use InstallShield, a tool that helps automate the creation of installation programs for Visual C++ projects You will also learn how installation programs install ActiveX controls and other COM components, and how the Microsoft Zero Administration for Windows (ZAW) initiative will affect program installation in the future Features of This Book The following features are designed to enhance the usefulness of this course: Each chapter opens with a "Before You Begin" section, which provides information about chapter prerequisites Each chapter is divided into lessons Most lessons contain O optimistic locking A recordset locking strategy in which records are left unlocked until explicitly updated The page containing a record is locked only while the program updates the record, not while a user is editing the record See also pessimistic locking P persistent Lasting between program sessions, or renewed when a new program session is begun pessimistic locking A recordset locking strategy in which a page is locked once a user begins editing a record on that page While the page is locked, no other user can change a record on that page The page remains locked until records are updated or the editing is canceled See also optimistic locking pixel The smallest addressable picture element (that is, a single dot) on a display screen or printed page platform The hardware and operating system that support an application A platform sometimes is considered as the hardware alone, as in the Intel x86 platform primary key In a database program, a field or group of fields that uniquely identifies a record in a table No two records in a table can have the same primary key value property The data associated with an object property page A grouping of properties presented as a tabbed page of a property sheet property sheet A type of dialog box that is generally used to modify the attributes of an external object, such as the current selection in a view A property sheet has three main elements: the containing dialog box, one or more property pages shown one at a time, and a tab at the top of each page that the user clicks to select that page An example of a property sheet is the Project Settings dialog box in Visual C++ proxy An interface-specific object that packages parameters for methods in preparation for a remote method call A proxy runs in the address space of the sender and communicates with a corresponding stub in the receiver's address space See also stub, marshaling, unmarshaling Q query A request for records from a data source For example, a query can be written that requests "all invoices for Joe Smith," where all records in an invoice table with the customer name "Joe Smith" would be selected See also recordset R radio button In graphical user interfaces, a round button operated by the user to toggle an option or choose from a set of related but mutually exclusive options raw data Unprocessed, typically unformatted data Raw data is a stream of bits that has not been filtered for commands or special characters More generally, it is information that has been collected but not evaluated read-only Describes information stored in such a way that it can be played back (read) but cannot be changed (written) record A collection of data about a single entity, such as an account or customer, stored in a table row A record consists of a group of contiguous columns (sometimes called fields) that contain data of various types See also recordset Record Field Exchange (RFX) The mechanism by which MFC ODBC classes transfer data between the field data members of a recordset object and the corresponding columns of an external data source See also DDX record view In form-based data-access applications, a form view object in which controls are mapped directly to the field data members of a recordset object, and indirectly to the corresponding columns in a query result or table on the data source recordset A set of records selected from a data source The records can be from a table, query, or stored procedure that accesses one or more tables A recordset can join two or more tables from the same data source, but not from different data sources See also record Red-green-blue (RGB) A mixing model, or method of describing colors, in light-based media such as color monitors RGB mixes percentages of light-based colors (red, green, and blue) to create other colors Windows defines these percentages as three 8-bit values called RGB values Zero percentage of all three colors, or an RGB value of (0,0,0), produces black and 100 percent of all three colors, or an RGB value of (255,255,255), produces white reference count A count of the number of pointers that access, or make reference to, an object, allowing for multiple references to a single object This number is decremented when a reference is removed; when the count reaches zero, the object's space in memory is freed referential integrity In database management, a set of rules that preserves the defined relationships between tables when records are entered or deleted For example, enforcing referential integrity would prevent a record from being added to a related table when no associated record in the primary table exists registry In 32-bit Windows, the database in which configuration information is registered This database takes the place of most configuration and initialization files for Windows and new Windows-based applications registry key A unique identifier assigned to each piece of information in the system registration database relational database A type of database or database management system that stores information in tables and conducts searches by using data in specified columns of one table to find additional data in another table remote server A COM server application, implemented as an executable file, that runs on a different computer from the client application using it See also in-process server, local server RFX See Record Field Exchange RGB See Red-green-blue rich edit control In MFC, a window in which the user can enter and edit text The text can be assigned character and paragraph formatting and can include embedded ActiveX objects root In a hierarchy of items, the single item from which all other items are descended The root item has nothing dominating it in the hierarchy S scrolling The process of moving a document in a window to permit viewing of any desired portion SEH See Structured Exception Handling semaphore A synchronization object that maintains a count between zero and a specified maximum value A semaphore's state is signaled when its count is greater than zero and nonsignaled when its count is zero The semaphore object is useful in controlling a shared resource that can support a limited number of users This object acts like a gate that counts the threads as they enter and exit a controlled area, and that limits the number of threads sharing the resource to a specified maximum number serialization Also referred to as object persistence In MFC, the process of writing or reading an object to or from a persistent storage medium, such as a disk file The basic idea of serialization is that an object should be able to write its current state, usually indicated by the value of its member variables, to persistent storage Later, the object can be recreated by reading, or deserializing, the object's state from storage server 1 In a network, a centrally administered computer that allows network access to all users An application or a process that responds to a client request server object An object that responds to a request for a service A given object can be a client for some requests, and a server for other requests shell A piece of software, usually a separate program, that provides communication between the user and the operating system For example, the Windows Program Manager is a shell program that interacts with MS-DOS Single document interface (SDI) A user interface architecture that allows a user to work with just one document at a time Windows Notepad is an example of an SDI application See also MDI single threading model A model in which all objects are executed on a single thread Contrasts with multithreaded applications See also apartment-model threading, free threading model smart pointer In C++, an object that implements the functionality of a pointer and additionally performs some action whenever an object is accessed through it Smart pointers are implemented by overloading the pointer-dereference (-> ) operator snapshot In MFC, a recordset that reflects a static view of the data as it existed at the time the snapshot was created See also dynaset, recordset SQL See Structured Query Language status bar A control bar at the bottom of a window, with a row of text output panes The status bar is usually implemented as a message line (for example, the standard menu help message line) or as a status indicator (for example, the CAP, NUM, and SCRL indicators) Structured Exception Handling (SEH) A mechanism for handling hardware- and software-generated exceptions that gives developers complete control over the handling of exceptions, provides support for debuggers, and is usable across all programming languages and computers Structured Query Language (SQL) A database sublanguage used to query, update, and manage relational databases stub 1 An interface-specific object that unpack-ages the parameters for that interface after they are marshaled across the process boundary, and makes the requested method call The stub runs in the address space of the receiver, and communicates with a corresponding proxy in the sender's address space A function with an empty body; used as a placeholder synchronization object An object in which the handle can be specified in one of the wait functions to coordinate the execution of multiple threads The state of a synchronization object is either signaled, which can allow the wait function to return, or nonsignaled, which can prevent the function from returning More than one process can have a handle of the same synchronization object, making interprocess synchronization possible See also mutex object, semaphore T tab control A common control used to present multiple pages of information or controls to a user; only one page at a time can be displayed tab order The order in which the TAB key moves the input focus from one control to the next within a dialog box Usually, the tab order proceeds from left to right in a dialog box, and from top to bottom in a radio group thread The basic entity to which the operating system allocates CPU time A thread can execute any part of the application's code, including a part currently being executed by another thread All threads of a process share the virtual address space, global variables, and operating system resources of the process toolbar A control bar based on a bitmap that contains a row of button images These buttons can act like pushbuttons, check boxes, or radio buttons See also status bar ToolTip A tiny pop-up window that presents a short description of a toolbar button's action ToolTips are displayed when the user positions the mouse over a button for a period of time type library A file or component within another file that contains type information about exposed objects Type libraries are created using either the MkTypLib utility or the MIDL compiler, and can be accessed through the ITypeLib interface U UDA See Universal Data Access UNC See Universal naming convention Uniform Resource Locator (URL) The address of a resource on the Internet URL syntax is in the form protocol://host/localinfo, where protocol specifies the means of fetching the object (such as HTTP or FTP), host specifies the remote location where the object resides, and localinfo is a string (often a file name) passed to the protocol handler at the remote location Universal Data Access (UDA) The Microsoft strategy for providing access to all types of information across the enterprise UDA provides high-performance access to a variety of information sources Universal naming convention (UNC) The standard format for paths that include a local area network file server, as in \\server\share\path\filename Universally unique identifier (UUID) A GUID that identifies a COM interface See also IID unmarshaling In COM, the process of unpacking parameters that have been sent across process boundaries URL See Uniform Resource Locater user-interface thread In Windows, a thread that handles user input and responds to user events independently of threads executing other portions of the application User-interface threads have a message pump and process messages received from the system See also worker thread UUID See Universally unique identifier V variant In Automation, an instance of the VARIANT datatype, which can represent values of many different types, such as integers, floats, Booleans, strings, pointers, and so on view A window object through which a user interacts with a document vtable A table of function pointers, such as an implementation of a class in C++ The pointers in the vtable point to the members of the interfaces that an object supports See also dual interface W Win32 platform A platform that supports the Win32 API These platforms include Intel Win32s, Windows NT, Windows 95, Windows 98, MIPS Windows NT, DEC Alpha Windows NT, and Power PC Windows NT window class A set of attributes that Windows uses as a template to create a window in an application Windows requires that an application supply a class name, the windowprocedure address, and an instance handle Other elements can be used to define default attributes for windows of the class, such as the shape of the cursor and the content of the menu for the window window handle In the Win32 API, a 32-bit value (assigned by Windows) that uniquely identifies a window An application uses this handle to direct the actions of functions to the window A window handle has the HWND data type; an application must use this type when declaring a variable that holds a window handle window procedure A function, called by the operating system, that controls the appearance and behavior of its associated windows The procedure receives and processes all messages to these windows wizard A special form of user assistance that guides a user through a difficult or complex task within an application For example, a database program can use wizards to generate reports and forms In Visual C++, the AppWizard generates a skeleton program for a new C++ application worker thread A thread that handles background tasks while a user continues to use an application Tasks such as recalculation and background printing are examples of worker threads See also user-interface thread World Wide Web (WWW) The portion of the global Internet that uses hypertext links to connect pages and resources in a way that lets a user reach any page from any other page WWW See World Wide Web ... skills necessary to develop solutions using Visual C++ 6. 0 This book addresses the objectives of the Microsoft Certified Solution Developer (MCSD) Exam 70- 0 16, "Designing and Implementing Desktop Applications with Microsoft Visual C++. .. Microsoft Visual C++ 6. 0 Starts Here This companion CD also contains the Microsoft Visual C++ 6. 0 Starts Here product to help you become more familiar with Visual C++ 6. 0 It is located in the MVC6SH folder (on the... reproduced or transmitted in any form or by any means without the written permission of the publisher Library of Congress Cataloging-in-Publication Data Desktop Applications with Microsoft Visual C++ 6. 0 : MCSD Training Kit / Microsoft Corporation