BN.com Gift Guide

MFC Answer Book: Solutions for Effective Visual C++ Applications

Paperback (Print)
Used and New from Other Sellers
Used and New from Other Sellers
from $1.99
Usually ships in 1-2 business days
(Save 96%)
Other sellers (Paperback)
  • All (24) from $1.99   
  • New (7) from $35.09   
  • Used (17) from $1.99   

Overview

The MFC Answer Book: Solutions for Effective Visual C++ Applications is written for Windows developers who want to go beyond Wizard-supplied functionality and incorporate more sophisticated and customized user interface features into their applications. This book will save you days of frustration by providing answers to more than 130 tough, real-world programming questions, such as

  • How do I make my application remember the last active document and automatically reopen it?
  • How do I dynamically replace the view displayed in a window with another kind of view?
  • How do I implement an expanding dialog box?
  • How do I embed a property sheet inside another window, such as a form view or a dialog box?
  • How do I display and manage a progress indicator in a status bar pane?
  • How do I implement advanced and customized printing features in my application?

The MFC Answer Book offers the shortest path from frequently encountered programming problems to corresponding step-by-step solutions that you can integrate immediately into your current project.

The question and answer format of this book makes it ideal for developers looking for quick answers to a pressing questions. In addition to providing a concise, concrete answer to each question--along with immediately reusable code--this book also contains in-depth discussions that provide a better understanding of the inner workings of MFC applications to help you sharpen your MFC programming skills. This book also explores many utility functions and classes that dramatically reduce the effort needed to add frequently asked-for improvements and customizations to your applications.

The comprehensive contents, combined with an extensive, cross-referenced index, makes it easy to zoom in on exactly the solution you need.

If you want to enhance your MFC skills and learn effective techniques that will allow you to add outstanding features to your Windows applications, there is no better resource than this book.

0201185377B04062001

Read More Show Less

Editorial Reviews

Booknews
A book/CD-ROM guide for Windows developers who want to go beyond Wizard-supplied functionality and incorporate customized user interface features into their applications. Material is presented in the form of some 130 real-world programming questions and step-by-step solutions. The accompanying CD-ROM contains source code and executable files for some 100 sample programs, plus MFC extension libraries. Assumes basic proficiency in C++, Visual C++, and MFC programming. Annotation c. by Book News, Inc., Portland, Or.
Davide Marcato

Beyond the Theory -- Put MFC to Work!

In my opinion, there are three categories of skills that a software developer needs to possess in order to successfully bring a software project to completion, correlated to one another by an intrinsic dependency.

The first is a clear understanding of the problem's domain under analysis, coupled with a solid grasp of the high-level paradigms that are going to be embraced to model the architecture of the solution. The second is a deep knowledge of the technologies, libraries and tools employed in the detailed design phase (and particularly in the implementation phase) of the development process. The third is a lot of direct experience amassed by applying the tools and technologies that were elected to have a role in the project in real world scenarios. Awareness and knowledge of the concepts and theoretical relations among the elements of the system constitute the first key step in the right direction, but alone they do not suffice to produce actual solutions to real problems.

By its very nature, the first skill crosses the borders between the diverse development tools and technologies -- it spans several languages (including the informal one spoken by the customer) and the command the programmer has on it increases proportionally with the accumulation of more positive experiences in any kind of software project, no matter how apparently unrelated to the current one they might seem. The second skill can be acquired first of all by reading a few well-focused books; speaking of MFC, many such titles have been populating the shelves of any respectable technical bookstore for several years. But when it comes to the third point, the scene suddenly darkens. Finding even extensive info on the goals and the workings of MFC is relatively easy, but on the road that takes one from that level to the utilization of the framework to accomplish real-world tasks, the programmer is generally left to his/her raw intuition.

Well, he was until Eugene Kain decided to take the time to write this book. The MFC Answer Book is organized as a large collection of frequently asked questions (FAQs) and programming problems accompanied by the detailed description of how the MFC classes (and the Visual C++ wizards) can be leveraged to build effective solutions. The questions are divided into categories based on the main class, the MFC-specific mechanism, or the user-interface feature they can be more closely associated with. Among the many categories you can find manners to customize the infamous document/view paradigm, manage documents, customizing dialog box elements, operating menus, toolbars and status bars, and coping with common issues of the printing and print preview mechanisms. For every FAQ, the question is first formulated in a concise format. Subsequently, the author provides the theoretical explanation of what the question really means and how the MFC machinery can accomplish it. Then the equivalent source code is presented in its entirety, coupled by both inline comments and step-by-step instructions. Occasionally, this part is followed by a section that delves deeper into the MFC architecture and unearths its interaction with the Windows APIs, obviously aimed at the more curious readers who wish to learn why the solution would work like it does. Eventually the "See Also" section suggests other FAQs covered by the book that are strictly related, and therefore would probably be a profitable read as a companion to the current one.

The underlying idea of this text is not new or particularly revolutionary: Other titles on the market clearly resemble the same structure and a similar solution-oriented perspective on MFC, of which Al William's MFC Black Magic (published by The Coriolis Group) in particular is worth mentioning. Moreover, most of the techniques explained do not emerge for their originality, and more often than not they had already been published in a substantially equivalent form on some Windows development magazine, on the Internet MFC FAQ, or on web sites specifically devoted to collecting short tips and code samples (the most famous being CodeGuru).

Despite this, I would advise developers of any experience who are directly involved in the creation of GUI MFC applications to add it to their personal bookshelves. The vastness of the spectrum of topics covered and the depth of the explanations make it suitable for even the most proficient MFC programmers, while the step-by-step approach followed in the descriptions of how to generate the actual code guarantees the usability by the less experienced practitioners.

Finally, even though the quality of the editing is lacking at times, room wasted by redundant screenshots, and code listings could have been easily reduced, the writing style flows pleasantly and you rarely find yourself rereading a paragraph because you did not understand it at first. Probably not a book that will leave a sign in history, but surely one of undeniable usefulness for real-world MFC programmers.
Dr. Dobb's Electronic Review of Computer Books

Read More Show Less

Product Details

  • ISBN-13: 9780201185379
  • Publisher: Addison-Wesley
  • Publication date: 8/6/1998
  • Pages: 704
  • Product dimensions: 7.20 (w) x 9.00 (h) x 1.50 (d)

Meet the Author

As a veteran computer engineer who has been developing professional Windows applications with MFC since 1992, Eugène Kain is attuned to the needs of Windows programmers. His extensive experience includes directing software projects, consulting, and designing and delivering advanced MFC training sessions for professional developers. He has written five books on Windows programming.

0201185377AB04062001

Read More Show Less

Read an Excerpt

Why Another Book on Microsoft Foundation Classes Programming?

To answer this question, let us look at a typical MFC programming scenario. First, you attend an MFC training session or read some introductory books on MFC programming. You quickly become able to write and customize small tutorial applications. AppWizard and ClassWizard allow you reach an unprecedented level of productivity. Your applications support the multiple document interface (MDI) and have a professional-looking user interface with a floating toolbar, a status bar, printing and print preview, and so on.

You then go back to work and start using MFC to produce great-looking applications. Code flows freely from your keyboard, the wizards work hard at your side, and life looks great under the MFC sun.

One day, you start wondering about how to implement new features that were not explicitly covered in the training session. For example:

  • Make your application remember the last active document and automatically reopen it.
  • Support multiple kinds of views on the same document and allow the user to explicitly open any kind of view.
  • Add ToolTips to the controls in a form view.
  • Dynamically switch the view displayed in a window to replace it with another kind of view.
  • Implement an expanding dialog box.
  • Embed a property sheet (tabbed dialog box) inside another window, such as a form view, a dialog box, or a mini frame window.
  • Display a progress indicator in a status bar pane.
  • Have a menu pop up when the user clicks a button on a toolbar or in a dialog box.
  • Support headers and footers in your print and print preview.
  • Display a custom Printing . . . dialog boxwith a progress indicator.

You feel that implementing these features cannot be that difficult: after all, you have already seen them in other Windows applications. But where do you start looking for an answer?

The solution may be as easy as knowing the specific MFC virtual functions that you must override to produce the desired effect or knowing the Windows messages you should trap and handle appropriately. For some features, however, more involved techniques may be needed—even to the point of tracing into MFC's source code to understand just where and how you can act to modify your application's default behavior.

One infuriating fact of life is that the answer to your particular question may be lying around somewhere: buried in some MFC programming book or magazine article, on the Microsoft Developer's Network CD-ROM, in the Microsoft Knowledge Base, in the various threads and mailing lists maintained on the Internet, or even in the online books or samples contained on the Visual C++ CD-ROM. The problem is this: How are you going to locate the most relevant and reliable source of information among all these resources? How are you going to find the solution you need right now? Introducing The MFC Answer Book

This book is intended to provide ready-to-use techniques that answer the most common real-world questions that typically confront MFC developers. The structure of this book is specifically designed to help you quickly locate the answers youire looking for and integrate the relevant solutions into your own programs.

The FAQ format of this book makes it ideally suited to the needs of the developer looking for a quick answer to a pressing question. At the same time, you will find that many techniques will give you a better understanding of the inner workings of MFC applications and more generally help you improve your MFC programming skills. In particular, the Explanations and Additional Comments sections often delve into the MFC source code or undocumented functions to explain how the techniques discussed work and how they differ from or integrate with MFC's default behavior. Key Features of This Book

Although most books about Visual C++ and MFC programming answer valid questions about MFC programming and provide useful tips if you read them from cover to cover, most of them are not structured in a way that allows you to quickly find an answer to a given problem. Moreover, even if you find the answer, it is likely to be buried inside a larger discussion and not readily available as a step-by-step technique that you can simply incorporate into your current project to add a required feature.

In contrast, The MFC Answer Book is specifically designed to help MFC developers solve their programming problems in the most efficient way:

  • This book is organized so that the table of contents will help you to quickly zoom in on the FAQs that answer your questions.
  • I have made every effort to build a convenient and comprehensive index that will direct you to all the pages relating to any keyword or function referenced in this book.
  • Each FAQ is written in a concise way that first gives you the step-by-step answer you need. Explanations and additional comments are deferred to later sections so that they do not get in the way of the solution but are readily available for those who want to go further than the cookbook recipe and wish to understand what goes on under the hood.
  • Each explanation comes with tested and reusable sample code that you can plug into your MFC application in a few minutes to integrate the required functionality immediately.
To summarize: The goal of this book is to offer you the shortest way from a problem to the corresponding step-by-step solution that you can integrate immediately into your current project. Who Should Read This Book

This book is written for all MFC developers who wish to solve their MFC-related problems and at the same time learn advanced MFC techniques that will allow them to add a range of sophisticated features to their applications.

This book assumes a basic proficiency both in the C++ language and in MFC programming as well as a knowledge of how to use the Visual C++ integrated development environment and tools such as AppWizard and ClassWizard. The Visual C++ wizards are discussed only when used in nonstandard ways to achieve a specific result.

To benefit fully from this book, you should already understand the basic MFC concepts presented in the Scribble tutorial described in the Visual C++ documentation: the document/view architecture, message maps, the UPDATE_COMMAND_UI mechanism, dialog data exchange (DDX), and so on. Typically, you will either have followed the Scribble tutorial, attended a training session in MFC programming, or read one of the many introductory books on this topic.

Of course, having a more extensive background in MFC programming will not hurt! Quite to the contrary. Based on feedback from reviewers and colleagues, I know that this book will also appeal to experienced MFC developers, who will find many useful techniques to add to their bag of MFC programming tricks.

Finally, reading this book will allow all MFC developers to improve their understanding of fundamental MFC concepts and sharpen their MFC programming skills. How To Use This Book

This book focuses on the 32-bit MFC version 4.x for Windows 95 and Windows NT. However, most techniques and concepts discussed here also apply to older versions of MFC. They should also remain valid for future MFC versions, because they rely on core MFC classes and behaviors that are not likely to evolve in a way that breaks existing code.

I tried to write this book so that it will become a flexible tool that you can use as you want to. This means that you can either read this book from cover to cover—I would certainly appreciate it if you do—or use it as a reference to look up only the specific topics that interest you. Most FAQs are cross-referenced to help you locate all the relevant information you might need even if you jump into the middle of the book.

However, before you start hunting for answers to your MFC questions, I suggest that you take a few minutes to read Chapter 0 (Terminology and Conventions) and Chapter 1 (Document/View Architecture Backgrounder) to make sure that we start on the same ground with respect to fundamental document/view architecture concepts. What Is on the CD-ROM

The companion CD-ROM contains source code and executables for all of the book's sample programs. The folder hierarchy is organized first by chapter number and then by project name. Thus, the AutoSaveDoc project for Chapter 2 is located in the d:\Chap02\AutoSaveDoc folder, where "d:" is your CD-ROM drive's letter.

All the executables are located under their respective chapter folders. For example, all the executable sample programs for Chapter 2 are located in the d:\Chap02 folder. The EkUtil.h and EkUtil.cpp files located at the root of the hierarchy contain the various helper Ek . . . . . . functions and classes that are presented throughout the book.

You can choose to copy the whole folder hierarchy from the CD-ROM to your hard disk, copy only the examples that are of interest to you, or access the files directly from the CD-ROM. If you copy files from the CD-ROM to your hard disk, remember to remove the read-only attribute from the files on your hard disk.

All sample programs have been compiled and tested under both Visual C++ 5.0 and Visual C++ 6.0. They will also work properly with Visual C++ 4.x, but you will have to manually create the appropriate .mdp project file. Note, however, that the .dsp project files on the CD-ROM have the Visual C++ 5.0 format: if you open them with Visual C++ 6.0, simply answer Yes to the dialog box asking whether you want to convert these files to the new format. Your Feedback Is Welcome

I have done my best to accurately present topics that I feel should be of interest to most MFC developers. However, if you think that a topic should be covered differently or should use another technique, don't hesitate to send me e-mail at ekain@awl.com. Also, e-mail me if you want to submit a topic idea or a technique of your own that solves a problem you have encountered, if you find an error or have any problem with this book, or if you have suggestions or want to discuss anything with me.

I can promise that I will read all e-mail messages, take them into account, and try to respond to each of them as soon as possible. Note, however, that I may not have the time to answer specific MFC programming questions. You can also visit my Web site at http://www.mfcfaq.com/ to get late-breaking information.

I hope that this book will make you enjoy MFC programming more than ever and help you deliver great applications.

Good luck with your MFC projects! —Eugène Kain, July 1998

Read More Show Less

Table of Contents

Foreword by Scot Wingo.

Preface.

Acknowledgments.

Terminology and Conventions.

Terminology Used in This Book.

Conventions Used in the Sample Code in This Book.

1. Document/View Architecture Backgrounder.

FAQ 1.1 What is the document/view architecture?

FAQ 1.2 What are the benefits of the document/view architecture?

FAQ 1.3 What components make up the document/view architecture, and how do they relate to each other?

FAQ 1.4 What is the role of the document?

FAQ 1.5 What is the role of the view?

FAQ 1.6 What is the role of the view’s frame window?

FAQ 1.7 What is the role of the document template?

FAQ 1.8 What is the role of the document template resource ID?

FAQ 1.9 How do the document/view architecture component objects get created?

FAQ 1.10 How does MFC route command messages?

FAQ 1.11 How does MFC implement the standard menu commands?

2. Documents and Document Templates.

Managing Document Templates.

FAQ 2.1 How should I create and reference multiple document templates in my application?

FAQ 2.2 How do I manage multiple document templates without having a dialog box pop up each time the user tries to create a new document?

FAQ 2.3 How do I create the resources associated with a new document template resource ID?

FAQ 2.4 How does MFC select the document template object to use when opening a file?

FAQ 2.5 How do I associate multiple file extensions with the same document or view class?

Managing Documents.

FAQ 2.6 How do I prevent an MDI application from opening a new (empty) document at start-up?

FAQ 2.7 How do I programmatically create a new (empty) document?

FAQ 2.8 How do I programmatically open an existing document file?

FAQ 2.9 How do I make my application remember the last active document and automatically reopen it?

FAQ 2.10 How do I make my documents autosave themselves without prompting the user?

FAQ 2.11 How do I implement a “Save all documents” menu command that does not prompt the user before saving each modified document?

FAQ 2.12 How do I programmatically close a document?

FAQ 2.13 How do I implement a “Close all documents” menu command?

Managing the Recent Files List (MRU).

FAQ 2.14 How do I customize the number of recent files shown in the “File” menu?

FAQ 2.15 How do I programmatically add a specific string to the Recent Files list?

FAQ 2.16 How do I intercept the selection of a Recent Files item by the user?

FAQ 2.17 How do I make my application automatically open the document that is at the top of the Recent Files list?

Miscellaneous Items.

FAQ 2.18 How do I get a pointer to the currently active document?

FAQ 2.19 How do I iterate through the list of all the currently opened documents?

FAQ 2.20 Why doesn’t my application register its document files with Windows Explorer, and how do I correct this situation?

3. Views and Frame Windows.

General Topics.

FAQ 3.1 How do I add a new kind of view or frame window to my application?

FAQ 3.2 How do I choose between implementing a specific behavior in the view class or in the view's frame window class?

Opening and Closing Views and Frame Windows.

FAQ 3.3 How do I programmatically open a view based on a specific document template?

FAQ 3.4 How do I open two (or more) specific views each time a new document is created?

FAQ 3.5 How do I programmatically close a view?

FAQ 3.6 How do I programmatically close all the views opened on a document?

FAQ 3.7 How do I prevent a view from being closed by the user? 137

Managing Size and Positions.

FAQ 3.8 How do I programmatically resize or reposition a view?

FAQ 3.9 How do I set the initial position and size of a view?

FAQ 3.10 How do I center my main application window?

FAQ 3.11 How do I center a view?

FAQ 3.12 How do I make a frame window nonresizable?

FAQ 3.13 How do I limit the maximum or minimum size of a view?

FAQ 3.14 How do I limit the repositioning of a view?

FAQ 3.15 How do I make a view initially appear minimized or maximized?

FAQ 3.16 How do I make my application start maximized or minimized?

FAQ 3.17 How do I make my main application window stay always on top of other windows?

FAQ 3.18 How do I make one of my views stay always on top of other views?

FAQ 3.19 How do I implement a full-screen view mode like the one in Visual C++ and Word?

Managing Captions, Icons, Cursors, and Background.

FAQ 3.20 How do I customize the captions of my views?

FAQ 3.21 How do I show a “modified” indicator in the captions of the views associated with a “dirty” document?

FAQ 3.22 How do I modify the icons associated with each kind of window in my application?

FAQ 3.23 How do I dynamically change the icon of my main application window ?

FAQ 3.24 How do I dynamically change the cursor for a view?

FAQ 3.25 How do I display an hourglass cursor during a lengthy operation?

FAQ 3.26 How do I change the background color of a view?

FAQ 3.27 How do I draw on the main application window background?

Form Views.

FAQ 3.28 How do I keep my form views synchronized with my other views?

FAQ 3.29 How do I make a form view initially appear with the exact size of the associated dialog resource?

FAQ 3.30 How do I use the UPDATE_COMMAND_UI mechanism in form views?

FAQ 3.31 How do I change the background color of a form view?

FAQ 3.32 How do I add ToolTips to the controls in a form view?

Splitter Windows.

FAQ 3.33 How do I program a window with both horizontal and vertical static splitter panes (three-way splitter)?

FAQ 3.34 How do I lock a splitter window so that the user cannot move the divider line?

FAQ 3.35 How do I programmatically resize the panes in a splitter window?

FAQ 3.36 How do I visually show the user which splitter pane contains the active view?

Switching Views.

FAQ 3.37 How do I dynamically switch the view displayed in an MDI child window or SDI main application window?

FAQ 3.38 How do I dynamically switch the view displayed in a splitter window?

Miscellaneous Items.

FAQ 3.39 How do I get a pointer to the active view?

FAQ 3.40 How do I get a pointer to the active frame window?

FAQ 3.41 How do I iterate through the list of all the views associated with a document?

4. Dialog Boxes.

General Topics.

FAQ 4.1 How do I set the initial position of a dialog box?

FAQ 4.2 How do I center a dialog box in relation to another window?

FAQ 4.3 How can a dialog box access the active document (or view) object?

FAQ 4.4 How do I control the background color of a dialog box?

FAQ 4.5 How do I add a preview area to (draw inside) a dialog box?

FAQ 4.6 How do I add an icon to a dialog box?

FAQ 4.7 How do I implement an expanding dialog box?

FAQ 4.8 How do I add a toolbar to a dialog box?

Managing Controls on a Dialog Box.

FAQ 4.9 How do I choose the control that will initially have the focus when a dialog box is displayed?

FAQ 4.10 How do I implement custom validation rules in a dialog box?

FAQ 4.11 How do I change the font and color of controls on my dialog box?

FAQ 4.12 How do I use the UPDATE_COMMAND_UI mechanism in dialog boxes?

FAQ 4.13 How do I add ToolTips support to the controls in a dialog box?

5. Property Sheets.

General Topics.

FAQ 5.1 How do I build and use a property sheet?

FAQ 5.2 How do I manage the Apply button in a property sheet?

FAQ 5.3 How do I programmatically change the active page in a property sheet?

FAQ 5.4 How do I customize the standard property sheet buttons?

FAQ 5.5 How do I control the size of my property sheet window?

Managing Tabs.

FAQ 5.6 How do I choose between a stacked row of tabs and a single row of scrolling tabs?

FAQ 5.7 How do I change the captions of the tabs of my property pages?

FAQ 5.8 How do I add icons to the tabs of my property pages?

Embedding Property Sheets.

FAQ 5.9 How do I embed a property sheet inside a dialog box?

FAQ 5.10 How do I embed a property sheet inside a form view?

FAQ 5.11 How do I embed a property sheet inside a splitter window pane?

FAQ 5.12 How do I embed a property sheet inside a miniframe window?

6. Toolbars and Status Bars.

Toolbars.

FAQ 6.1 How do I add one or more toolbars to my main frame window or to a view’s frame window?

FAQ 6.2 What are the various options available for controlling the position, orientation, and general behavior of my toolbars?

FAQ 6.3 How do I programmatically dock a toolbar next to another one?

FAQ 6.4 How do I add a combo box to a toolbar?

FAQ 6.5 How do I add text labels to my toolbar buttons?

FAQ 6.6 How do I implement a menu that allows users to select the toolbars they want to see?

FAQ 6.7 How do I allow users to choose the toolbar they want to see by selecting it in a popup menu that appears when they right-click on a docking zone?

FAQ 6.8 How do I dynamically switch between different toolbars?

Status Bars.

FAQ 6.9 How do I add a custom status bar to a view's frame window?

FAQ 6.10 How do I update the text of my status bar panes?

FAQ 6.11 How do I customize my status bar font?

FAQ 6.12 How do I draw in a status bar pane?

FAQ 6.13 How do I maximize the message pane when displaying menu prompts?

FAQ 6.14 How do I display a progress indicator in a status bar?

General Control Bar Topics.

FAQ 6.15 How do I programmatically show or hide a control bar?

FAQ 6.16 How do I set the caption of a floating control bar?

FAQ 6.17 How do I save and restore the position and state of my control bars?

FAQ 6.18 How do I create custom control bars?

7. Menus.

FAQ 7.1 How do I handle several distinct menu commands with a single function?

FAQ 7.2 How do I implement a right-button popup menu (context menu)?

FAQ 7.3 How do I display a popup menu when the user clicks a button on a toolbar?

FAQ 7.4 How do I display a popup menu when the user clicks a button in a dialog box?

FAQ 7.5 How do I implement an owner-drawn menu?

8. Printing and Print Preview.

FAQ 8.1 What is the MFC printing architecture?

FAQ 8.2 How do I implement printing and print preview in my MFC application?

FAQ 8.3 How do I print a document whose page length is not known in advance (on-the-fly pagination)?

FAQ 8.4 How do I predict page breaks as Microsoft Word does?

FAQ 8.5 How do I programmatically change the printing orientation (portrait versus landscape) on-the-fly?

FAQ 8.6 How do I print without prompting the user with the standard Print dialog box?

FAQ 8.7 How do I customize the standard Print dialog box and retrieve the options selected by the user?

FAQ 8.8 How do I customize the Printing . . . dialog box?

FAQ 8.9 How do I stop or abort a print job?

FAQ 8.10 How do I implement print preview in shades of gray for a monochrome printer?

FAQ 8.11 How do I distinguish between drawing, print preview, and actual printing in my code?

Appendix A Utility Functions and Classes.

Appendix B Bibliography and Additional Resources.

Index. 0201185377T04062001

Read More Show Less

Preface

Why Another Book on Microsoft Foundation Classes Programming?

To answer this question, let us look at a typical MFC programming scenario. First, you attend an MFC training session or read some introductory books on MFC programming. You quickly become able to write and customize small tutorial applications. AppWizard and ClassWizard allow you reach an unprecedented level of productivity. Your applications support the multiple document interface (MDI) and have a professional-looking user interface with a floating toolbar, a status bar, printing and print preview, and so on.

You then go back to work and start using MFC to produce great-looking applications. Code flows freely from your keyboard, the wizards work hard at your side, and life looks great under the MFC sun.

One day, you start wondering about how to implement new features that were not explicitly covered in the training session. For example:

  • Make your application remember the last active document and automatically reopen it.
  • Support multiple kinds of views on the same document and allow the user to explicitly open any kind of view.
  • Add ToolTips to the controls in a form view.
  • Dynamically switch the view displayed in a window to replace it with another kind of view.
  • Implement an expanding dialog box.
  • Embed a property sheet (tabbed dialog box) inside another window, such as a form view, a dialog box, or a mini frame window.
  • Display a progress indicator in a status bar pane.
  • Have a menu pop up when the user clicks a button on a toolbar or in a dialog box.
  • Support headers and footers in your print and print preview.
  • Display a custom Printing . . . dialog box with a progress indicator.

You feel that implementing these features cannot be that difficult: after all, you have already seen them in other Windows applications. But where do you start looking for an answer?

The solution may be as easy as knowing the specific MFC virtual functions that you must override to produce the desired effect or knowing the Windows messages you should trap and handle appropriately. For some features, however, more involved techniques may be needed--even to the point of tracing into MFC's source code to understand just where and how you can act to modify your application's default behavior.

One infuriating fact of life is that the answer to your particular question may be lying around somewhere: buried in some MFC programming book or magazine article, on the Microsoft Developer's Network CD-ROM, in the Microsoft Knowledge Base, in the various threads and mailing lists maintained on the Internet, or even in the online books or samples contained on the Visual C++ CD-ROM. The problem is this: How are you going to locate the most relevant and reliable source of information among all these resources? How are you going to find the solution you need right now?

Introducing The MFC Answer Book

This book is intended to provide ready-to-use techniques that answer the most common real-world questions that typically confront MFC developers. The structure of this book is specifically designed to help you quickly locate the answers youire looking for and integrate the relevant solutions into your own programs.

The FAQ format of this book makes it ideally suited to the needs of the developer looking for a quick answer to a pressing question. At the same time, you will find that many techniques will give you a better understanding of the inner workings of MFC applications and more generally help you improve your MFC programming skills. In particular, the Explanations and Additional Comments sections often delve into the MFC source code or undocumented functions to explain how the techniques discussed work and how they differ from or integrate with MFC's default behavior.

Key Features of This Book

Although most books about Visual C++ and MFC programming answer valid questions about MFC programming and provide useful tips if you read them from cover to cover, most of them are not structured in a way that allows you to quickly find an answer to a given problem. Moreover, even if you find the answer, it is likely to be buried inside a larger discussion and not readily available as a step-by-step technique that you can simply incorporate into your current project to add a required feature.

In contrast, The MFC Answer Book is specifically designed to help MFC developers solve their programming problems in the most efficient way:

  • This book is organized so that the table of contents will help you to quickly zoom in on the FAQs that answer your questions.
  • I have made every effort to build a convenient and comprehensive index that will direct you to all the pages relating to any keyword or function referenced in this book.
  • Each FAQ is written in a concise way that first gives you the step-by-step answer you need. Explanations and additional comments are deferred to later sections so that they do not get in the way of the solution but are readily available for those who want to go further than the cookbook recipe and wish to understand what goes on under the hood.
  • Each explanation comes with tested and reusable sample code that you can plug into your MFC application in a few minutes to integrate the required functionality immediately.
To summarize: The goal of this book is to offer you the shortest way from a problem to the corresponding step-by-step solution that you can integrate immediately into your current project.

Who Should Read This Book

This book is written for all MFC developers who wish to solve their MFC-related problems and at the same time learn advanced MFC techniques that will allow them to add a range of sophisticated features to their applications.

This book assumes a basic proficiency both in the C++ language and in MFC programming as well as a knowledge of how to use the Visual C++ integrated development environment and tools such as AppWizard and ClassWizard. The Visual C++ wizards are discussed only when used in nonstandard ways to achieve a specific result.

To benefit fully from this book, you should already understand the basic MFC concepts presented in the Scribble tutorial described in the Visual C++ documentation: the document/view architecture, message maps, the UPDATE_COMMAND_UI mechanism, dialog data exchange (DDX), and so on. Typically, you will either have followed the Scribble tutorial, attended a training session in MFC programming, or read one of the many introductory books on this topic.

Of course, having a more extensive background in MFC programming will not hurt! Quite to the contrary. Based on feedback from reviewers and colleagues, I know that this book will also appeal to experienced MFC developers, who will find many useful techniques to add to their bag of MFC programming tricks.

Finally, reading this book will allow all MFC developers to improve their understanding of fundamental MFC concepts and sharpen their MFC programming skills.

How To Use This Book

This book focuses on the 32-bit MFC version 4.x for Windows 95 and Windows NT. However, most techniques and concepts discussed here also apply to older versions of MFC. They should also remain valid for future MFC versions, because they rely on core MFC classes and behaviors that are not likely to evolve in a way that breaks existing code.

I tried to write this book so that it will become a flexible tool that you can use as you want to. This means that you can either read this book from cover to cover--I would certainly appreciate it if you do--or use it as a reference to look up only the specific topics that interest you. Most FAQs are cross-referenced to help you locate all the relevant information you might need even if you jump into the middle of the book.

However, before you start hunting for answers to your MFC questions, I suggest that you take a few minutes to read Chapter 0 (Terminology and Conventions) and Chapter 1 (Document/View Architecture Backgrounder) to make sure that we start on the same ground with respect to fundamental document/view architecture concepts.

What Is on the CD-ROM

The companion CD-ROM contains source code and executables for all of the book's sample programs. The folder hierarchy is organized first by chapter number and then by project name. Thus, the AutoSaveDoc project for Chapter 2 is located in the d:\Chap02\AutoSaveDoc folder, where "d:" is your CD-ROM drive's letter.

All the executables are located under their respective chapter folders. For example, all the executable sample programs for Chapter 2 are located in the d:\Chap02 folder. The EkUtil.h and EkUtil.cpp files located at the root of the hierarchy contain the various helper Ek . . . . . . functions and classes that are presented throughout the book.

You can choose to copy the whole folder hierarchy from the CD-ROM to your hard disk, copy only the examples that are of interest to you, or access the files directly from the CD-ROM. If you copy files from the CD-ROM to your hard disk, remember to remove the read-only attribute from the files on your hard disk.

All sample programs have been compiled and tested under both Visual C++ 5.0 and Visual C++ 6.0. They will also work properly with Visual C++ 4.x, but you will have to manually create the appropriate .mdp project file. Note, however, that the .dsp project files on the CD-ROM have the Visual C++ 5.0 format: if you open them with Visual C++ 6.0, simply answer Yes to the dialog box asking whether you want to convert these files to the new format.

Your Feedback Is Welcome

I have done my best to accurately present topics that I feel should be of interest to most MFC developers. However, if you think that a topic should be covered differently or should use another technique, don't hesitate to send me e-mail at ekain@awl.com. Also, e-mail me if you want to submit a topic idea or a technique of your own that solves a problem you have encountered, if you find an error or have any problem with this book, or if you have suggestions or want to discuss anything with me.

I can promise that I will read all e-mail messages, take them into account, and try to respond to each of them as soon as possible. Note, however, that I may not have the time to answer specific MFC programming questions. You can also visit my Web site at http://www.mfcfaq.com/ to get late-breaking information.

I hope that this book will make you enjoy MFC programming more than ever and help you deliver great applications.

Good luck with your MFC projects!

--Eugène Kain, July 1998

0201185377P04062001

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)