> online showcase > books > Mastering Visual C++ 6

Mastering Visual C++ 6, Third Edition Mastering Visual C++ 6, Third Edition

By Michael J. Young

Published by Sybex (now Wiley)
Pages: 1397, plus a companion CD
ISBN: 0-7821-2273-6

This tutorial and reference book provides a comprehensive, step-by-step guide to version 6 of Microsoft's Visual C++ development environment. This is now the third edition of Mastering Visual C++ (the fourth edition if you count the predecessor book Windows Programming with Microsoft C++), and it has grown to almost 1400 pages.

Microsoft Visual C++ has evolved into an incredibly powerful programming environment. However, if you're relatively new to C++ and you haven't been evolving as a C++ programmer along with VC++, learning Version 6 of this product can seem an overwhelming task. That's why I wrote this book. Although I assume you know some standard procedural C programming, you really don't need to know either C++ or Windows programming. The early chapters provide a crash course on C++, teaching you just what you need to know to effectively use VC++ for writing Windows programs. The remainder of the book then shows you how to use the essential VC++ tools, together with the Microsoft Foundation Classes (MFC). Following the step-by-step instructions, you'll be surprised how quickly and easily you'll be able to create truly sophisticated Windows programs. I've been working on this book over the past seven years, and I've incorporated a lot of feedback from readers. (My thanks to the many readers who have e-mailed me!) In creating the latest edition, I spent several months updating the chapters to incorporate the many significant changes found in VC++ 6. I also added a new chapter on programming and using ActiveX controls because of their importance in creating Web pages. The publisher, Sybex, did a superb job in producing this book, and I must say that I am proud of the final result.

Topics on this page:


Contents

Introduction -- Read an excerpt from the Introduction.

Part I: Introduction to Microsoft Visual C++ 6

Chapter 1: Setting Up the Software

Chapter 2: Creating a Program Using the Microsoft Developer Studio

Part II: Introduction to C++

Chapter 3: Moving to C++

Chapter 4: Defining C++ Classes

Chapter 5: Deriving C++ Classes

Chapter 6: Overloading, Copying, and Converting

Chapter 7: Using C++ Templates

Chapter 8: Handling Exceptions in C++

Part III: Windows GUI Programming with the MFC Library

Chapter 9: Generating a Windows GUI Program

Chapter 10: Implementing the View

Chapter 11: Implementing the Document

Chapter 12: Storing Documents in Disk Files

Chapter 13: Scrolling and Splitting Views

Chapter 14: Including Docking Toolbars and Status Bars

Chapter 15: Creating Custom Dialog Boxes

Chapter 16: Writing Dialog-Based Applications

Chapter 17: Writing Multiple Document Applications

Chapter 18: Performing Character I/O

Chapter 19: Using Drawing Functions

Chapter 20: Using Bitmaps and Bit Operations

Chapter 21: Printing and Print Previewing

Chapter 22: Using Multiple Threads

Chapter 23: Communicating Among Processes

Chapter 24: Using OLE

Chapter 25: Creating and Using ActiveX Controls

Companion CD


Download Example Source Code

If you purchased Mastering Visual C++ 6 without a companion CD, you can download the complete source code for the example programs. Unlike the CD, the downloaded source code doesn't include the executable or intermediate source files—you'll therefore need to build each program before you can run it.

The source files are contained in MVC6.ZIP. I recommend creating a new folder (perhaps named MVC6) and unzipping the files into this folder. When you unzip, be sure to preserve the original folder names and structure, which are stored in the ZIP file.

Download MVC6.ZIP (894KB)


Errors

Note that some or all of these errors might have been corrected in more recent printings of the book.

Page 11: "Using the Companion CD"

The information in this section is correct. However, here are some additional tips that might be helpful:

  • The project folders (for example, \Axcont, \Axctrl, \Bitdemo, \Contdemo, and \Cpp) are all contained within the \Examples folder on the CD, not in the root of the CD.
  • When you copy files from a CD to your hard drive, the read-only attribute for each file is usually set. If you've copied a project folder to your hard disk and if you want to modify the project, you should first turn off the read-only attribute for all the files contained in the project folder on your hard disk. You can switch off the read-only attribute for a single file by right-clicking it in Windows Explorer, choosing Properties from the pop-up menu, and unchecking the Read-Only option. You can also switch off the read-only attribute for all the files you copied to your hard disk in one fell swoop, by following these steps:
    1. Start an MS-DOS session.
    2. At the DOS prompt, change to the folder on your hard drive that contains the files from the CD. Make sure that you have changed to the right folder, so you don't inadvertently remove read-only protection from the wrong files!
    3 . Issue the following command at the DOS prompt:
    attrib -r *.* /s
    This will remove the read-only attribute from all files in the current folder and in all subfolders of the current folder.
  • The AxCont.exe program on the CD won't run until the ActiveX control it displays has been registered on your computer. As explained in Chapter 25, the ActiveX control gets registered automatically when you build the AXCtrl project (this is the project that creates the ActiveX control that AxCont.exe displays). Therefore, to run AxCont.exe you must first build the AxCtrl project in Visual C++. If you're working with the project from the CD, which has already been built, you can force Visual C++ to rebuild it—thus registering the ActiveX control—by choosing Rebuild All on the Build menu.
  • As stated in "Using the Companion CD," you can copy any of the source or program files directly from the companion CD to your hard disk using normal Windows or DOS commands (all files are provided in uncompressed format). The publisher also added the Mastvc6.exe program to the root of the CD. You can run this program to copy all of the source and program files to your CD. Note that this program simply provides an alternative way to copy the files—you don't need to use it. For complete instructions on Mastvc6.exe and for other information about the companion CD, see the file Readme.txt in the CD root.

Page 93, line of code at top

delete PRectangle;

should be

delete PRect;


Page 205, first and second line

The phrase

the throw "out of memory; statement

should be

the throw "out of memory"; statement


Page 283

Change "To do this, open the file MiniDraw.h..." to "To do this, open the file MiniDrawView.h..."


Page 351

After you add the #include <afxtempl.h> line to StdAfx.h as instructed, you might need to issue the Build All command to force VC++ to recompile this header file. For some reason (probably due to the header file being precompiled), if you use the normal Build command VC++ fails to recompile this file, even though you modified it.


Page 423, last paragraph (above the NOTE)

"GetNewView then returns a pointer..." should be "GetNextView then returns a pointer..."


Page 793, 3rd paragraph from bottom

"it calls CDC::GetLength" should be "it calls CDC:GetTextExtent"


Page 807, beginning of paragraph in middle of page

Change "Although OnDraw displays..." to "Although OnChar displays..."


The C++ code in the book:

The publisher's desktop publishing software replaced each occurrence of the decrement operator (--) with a single dash character (—). A dash isn't even a valid C++ character, although it looks similar to a minus sign. So be on the lookout for this error, and if you're typing in the code, be sure to type -- rather than - when you see a dash. BTW, the code on the companion CD doesn't have this error.

All of these errors occur within the code expression that should read

while (Index--)

Here are the places in the book where the error occurs:

  • 354, near center
  • 358, 1/3 down
  • 373, 3/4 down
  • 381, near top
  • 411, 3/4 down
  • 419, near top
  • 485, 2/3 down
  • 493, 1/3 down
  • 545, 3/4 down
  • 555, near center
  • 967, near bottom
  • 1080, near center
  • 1208, 3/4 down
  • 1211, near top
  • 1223, 3/4 down
  • 1224, near center
  • 1231, near bottom
  • 1241, near top

Left inside back cover of the book: This material was evidently written by an editor who was not very familiar with the purpose and features of the example programs! Here is a corrected version of this information:

Using the Companion CD

The Mastering Visual C++ 6 companion CD contains all the source code and executable files for the example programs provided in this book. You can use these files to save typing when working through the exercises given in the book, to explore the features of the example programs, and to experiment with additional programming techniques. You can also use them as a basis for creating your own programs. For more information, see the section "Using the Companion CD" in Chapter 1, as well as the file Readme.txt in the root folder of the CD.

Program Name Filename
AXCont—An ActiveX control container program that displays the AXCtrl ActiveX control AXCont.exe
AXCtrl—An example ActiveX control AXCtrl.ocx
BitDemo—A program that illustrates the techniques for designing, displaying, and manipulating bitmaps BitDemo.exe
ContDemo—A basic OLE container program (can be used to embed drawings created by the ServDemo program) ContDemo.exe
Cpp—A folder (not a program) that contains all the code listings from Part II of the book  
DlgDemo—A simple dialog-based program DlgDemo.exe
Echo—A program that illustrates the basic techniques for reading characters from the keyboard and echoing them in a window Echo.exe
FontDemo—A program that displays and exchanges information with a modal dialog box FontDemo.exe
FormDemo—A form-view program, which is a full-featured program based on a dialog box FormDemo.exe
Greet—A simple console (that is, character-mode) program Greet.exe
Mandel—A program that generates a fractal pattern to illustrate the techniques for drawing points, as well as several other graphics drawing techniques Mandel.exe
MandelMT—A multithreaded version of the Mandel program MandelMT.exe
MiniDraw 1 (MiniDrw1 folder)—The first version of the MiniDraw program, a simple drawing application that illustrates the techniques for creating a full-featured MFC Windows program and for drawing graphics. This version lets you draw only straight lines. MiniDraw.exe
MiniDraw 2 (MiniDrw2 folder)—The second version of the MiniDraw program, which stores the drawn lines and adds undo and delete commands MiniDraw.exe
MiniDraw 3 (MiniDrw3 folder)—The third version of the MiniDraw program, which adds file I/O MiniDraw.exe
MiniDraw 4 (MiniDrw4 folder)—The fourth version of the MiniDraw program, which adds scrolling capability, as well as a split box that allows you to divide the window into two panes MiniDraw.exe
MiniDraw 5 (MiniDrw5 folder)—The fifth version of the MiniDraw program, which adds a docking toolbar and a status bar to the program interface MiniDraw.exe
MiniDraw 6 (MiniDrw6 folder)—The sixth version of the MiniDraw program, which adds new shapes to the figures that you can draw (lines, rectangles, rounded rectangles, and circles) and lets you adjust the line thickness and choose the drawing color MiniDraw.exe
MiniDraw 7 (MiniDrw7 folder)—The seventh and final version of the MiniDraw program, which adds printing and print previewing MiniDraw.exe
MiniEdit 1 (MiniEdt1 folder)—The first version of the MiniEdit program, which illustrates the techniques for creating a text editor. This version provides the basic text editing commands. MiniEdit.exe
MiniEdit 2 (MiniEdt2 folder)—The second version of the MiniEdit program, which adds file I/O MiniEdit.exe
MiniEdit 3 (MiniEdt3 folder)—An MDI (multiple document interface) version of the MiniEdit program, which lets you open and edit several text files simultaneously MiniEdit.exe
ServDemo—A basic OLE server program, which is based on the MiniDraw program and allows OLE container programs (such as ContDemo) to embed drawings ServDemo.exe
TabDemo—A program that displays a tabbed dialog box TabDemo.exe
TextDemo—A program that demonstrates the main steps for choosing fonts and displaying lines of text in a window TextDemo.exe
WinGreet—A basic MFC Windows application WinGreet.exe

Valid HTML 4.01 Transitional