Programming under Windows is a lot like trying to find your way through a complex maze stocked with deadly traps and ravenous beasts. One wrong step and you're dead. The Windows maze is a dark place, indeed, so dark that it's darn near impossible to see where you're going. And every time you think you see the exit, something drags you back into the dark.
Because you bought this book, you're probably a veteran of the Windows dungeon. You've already dulled your programming blade battling thousands of pages of Windows documentation. You've treaded carefully through dank corridors paved with obscure technical jargon, stepped around secret trap doors (and probably fallen into a few) hiding incomprehensible program bugs, and yearned for just a glimmer of light just a spark to stave off the ever-encroaching darkness.
Luckily, people like you and I programmers who want to get their work done more quickly and easily can now see a light around the next bend. Microsoft has released version 5.0 of their popular Visual C++ development environment, and, thanks to Microsoft Foundation Classes (MFC), which is included with the Visual C++, programming Windows applications with C++ has never been easier.
What is MFC? MFC is an object-oriented library that encapsulates almost the entire Windows API. Using MFC, you can display a fully functional window on-screen with only a few program lines. Moreover, Visual C++ includes MFC tools like AppWizard, ClassWizard, and ActiveX ControlWizard that make starting a new MFC project as easy as a few mouse clicks.
This book is not an introductory text for programmers interested in learning C++ programming. To understand the lessons included here, you must have a working knowledge of C++ and be somewhat familiar with Visual C++'s development system. In addition, you should have a good grasp of object-oriented programming concepts. Although previous Windows programming experience is helpful, you can probably get by without it. Still, you'll want to have a good Windows programming manual at your side as you work through the programs in this book.
To compile and run the programs on this book's disk, and to get the most out of the upcoming lessons, you must have the following:
As always, the faster your processor, the better. Fast processors mean fast compiles and zippy programs. This is especially true for Windows programs, because Windows pushes your hardware to the limits.
This book is divided into parts, each of which concentrates on a specific area of MFC programming. The five parts feature many hands-on programming projects and are listed below with a brief description of their contents:
The programs in this book were written with Visual C++ 5.0. This book assumes your copy of Visual C++ was installed using the default settings and directories. If you've changed any of the default settings or directories and are not sure how to fix errors that may result from these changes, you should reinstall Visual C++.
The programs that follow are organized on the book's CD-ROM by chapter. Each chapter's programs are found in their own directory on the CD-ROM. The
programs in Chapter 2 are in the CHAP02 directory; the programs in Chapter 3 are in the CHAP03 directory, and so on. To compile the programs for a specific
chapter, copy all of the files from the chapter's directory to your hard drive. Then start Visual C++ and load the .dsw workspace file for the program that you want
to compile. Finally, choose the Build, Build command to compile and link the program.
For further information on creating and building projects, please refer to your Visual C++ 5.0 documentation.
As every developer knows, a good program is virtually crash proof. Error-checking must be done for every action that might fail, and appropriate error messages must be given to the user. Unfortunately, good error-checking requires a lot of extra program code. For the programmer working on his next magnum opus, this is all just part of the game. But for an author writing a programming book, this extra code has different implications.
A programming book should present its topics in as clear a manner as possible. This means featuring programs with source code not obscured by a lot of details that don't apply directly to the topic at hand. For this reason, the programs in this book do not always employ proper error-checking. User input might sometimes go unverified, dynamic construction of objects is assumed to be successful, and (horror of horrors) pointers are not always checked for validity.
In short, if you use any of the code in this book in your own programs, it's up to you to add whatever error-checking might have been left out. Never assume anything in your programs. Any place in your code that you arent 100 percent confident of your program's state, you must add error-checking to ensure that the program doesn't come crashing down on your users. Just because this book's author may have been lax in his error-checking (for good reasons), does not let you off the hook.
Now that you have some idea of what's ahead, it's time to start programming with MFC. You'll soon discover that, not only does MFC programming take much of the sting out of creating Windows applications, but it also enhances your understanding of object-oriented programming techniques. And, best of all, programming with MFC is fun.
Conventions Used in This Book
Que has over a decade of experience developing and publishing the most successful computer books available. With that experience, weve learned what special features help readers the most. Look for these special features throughout the book to enhance your learning experience.
Several type and font conventions are used in this book to help making reading it easier:
Tips present short advice on a quick or often overlooked procedure. These include shortcuts that can save you time.
Notes provide additional information that may help you avoid problems, or offer advice that relates to the topic.
Cautions warn you about potential problems that a procedure may cause, unexpected results, and mistakes to avoid.
See these cross-references for more information on a particular topic.