Sams Teach Yourself Visual
C++® 6 in 21 Days
Copyright © 1998 by Sams Publishing
All rights reserved. No part of this book shall be reproduced, stored in a retrieval system, or transmitted by any means, electronic, mechanical, photocopying, recording, or otherwise, without written permission from the publisher. No patent liability is assumed with respect to the use of the information contained herein. Although every precaution has been taken in the preparation of this book, the publisher and author assume no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein.
International Standard Book Number: 0-672-31240-9
Library of Congress Catalog Card Number: 98-84508
Printed in the United States of America
First Printing: August, 1998
01 |
00 |
99 |
98 |
4 |
3 |
2 |
1 |
Trademarks
All terms mentioned in this book that are known to be trademarks or service marks have been appropriately capitalized. Sams Publishing cannot attest to the accuracy of this information. Use of a term in this book should not be regarded as affecting the validity of any trademark or service mark.
Visual C++ is a registered trademark of Microsoft Corporation.
Warning and Disclaimer
Every effort has been made to make this book as complete and as accurate as possible, but no warranty or fitness is implied. The information provided is on an “as is” basis. The authors and the publisher shall have neither liability nor responsibility to any person or entity with respect to any loss or damages arising from the information contained in this book.
EXECUTIVE EDITOR
Brad Jones
ACQUISITIONS EDITOR
Kelly Marshall
DEVELOPMENT EDITOR
Matt Purcell
MANAGING EDITOR
Jodi Jensen
PROJECT EDITOR
Dana Rhodes Lesh
COPY EDITOR
Kris Simmons
INDEXER
Erika Millen
TECHNICAL EDITOR
Larry Richardson
PRODUCTION
Marcia Deboy
Michael Dietsch
Jennifer Earhart
Cynthia Fields
Susan Geiselman
Overview
|
Introduction |
1 |
WEEK 1 AT A GLANCE |
5 |
|
Day 1 |
The Visual C++ Development Environment—Building Your First |
|
|
Visual C++ Application |
7 |
2 |
Using Controls in Your Application |
25 |
3 |
Allowing User Interaction—Integrating the Mouse and Keyboard in |
|
|
Your Application |
47 |
4 |
Working with Timers |
67 |
5 |
Getting User Feedback—Adding Dialog Boxes to Your Application |
83 |
6 |
Creating Menus for Your Application |
105 |
7 |
Working with Text and Fonts |
121 |
WEEK 1 IN REVIEW |
143 |
|
WEEK 2 AT A GLANCE |
147 |
|
Day 8 |
Adding Flash—Incorporating Graphics, Drawing, and Bitmaps |
149 |
9 |
Adding ActiveX Controls to Your Application |
179 |
10 |
Creating Single Document Interface Applications |
199 |
11 |
Creating Multiple Document Interface Applications |
229 |
12 |
Adding Toolbars and Status Bars |
243 |
13 |
Saving and Restoring Work—File Access |
279 |
14 |
Retrieving Data from an ODBC Database |
315 |
WEEK 2 IN REVIEW |
337 |
|
WEEK 3 AT A GLANCE |
341 |
Day 15 |
Updating and Adding Database Records Through ADO |
343 |
16 |
Creating Your Own Classes and Modules |
379 |
17 |
Sharing Your Functionality with Other Applications—Creating DLLs 405 |
18 |
Doing Multiple Tasks at One Time—Multitasking |
429 |
19 |
Building Your Own Widgets—Creating ActiveX Controls |
473 |
20 |
Internet Applications and Network Communications |
495 |
21 |
Adding Web Browsing Functionality to Your Applications |
521 |
WEEK 3 IN REVIEW |
537 |
|
APPENDIXES |
541 |
|
A |
C++ Review |
541 |
B |
Answers |
579 |
C |
Printing and Print Previewing |
637 |
D |
Understanding and Exception Handling |
661 |
E |
Using the Debugger and Profiler |
677 |
F |
Using MFC’s Helper Classes |
699 |
|
Index |
731 |
Contents |
|
INTRODUCTION |
1 |
WEEK 1 AT A GLANCE |
5 |
DAY 1 THE VISUAL C++ DEVELOPMENT ENVIRONMENT—BUILDING YOUR FIRST |
|
VISUAL C++ APPLICATION |
7 |
The Visual C++ Development Environment............................................................ |
8 |
The Output Pane ................................................................................................ |
9 |
The Editor Area .................................................................................................. |
9 |
Menu Bars ........................................................................................................ |
10 |
Rearranging the Developer Studio Environment ............................................ |
10 |
Starting Your First Project .................................................................................... |
11 |
Creating the Project Workspace ...................................................................... |
11 |
Using the Application Wizard to Create the Application Shell ...................... |
12 |
Designing Your Application Window .................................................................... |
15 |
Adding Code to Your Application ........................................................................ |
17 |
Finishing Touches .................................................................................................. |
20 |
Creating the Dialog Box Icon .......................................................................... |
20 |
Adding Maximize and Minimize Buttons........................................................ |
21 |
Summary ................................................................................................................ |
22 |
Q&A ...................................................................................................................... |
22 |
Workshop .............................................................................................................. |
23 |
Quiz .................................................................................................................. |
23 |
Exercise ............................................................................................................ |
23 |
DAY 2 USING CONTROLS IN YOUR APPLICATION |
25 |
The Basic Windows Controls ................................................................................ |
26 |
The Static Text Control .................................................................................... |
26 |
The Edit Box Control ...................................................................................... |
26 |
The Command Button Control ........................................................................ |
27 |
The Check Box Control.................................................................................... |
27 |
The Radio Button Control ................................................................................ |
27 |
The Drop-Down List Box Control .................................................................. |
27 |
Adding Controls to Your Window ........................................................................ |
27 |
Creating the Application Shell and Dialog Layout .......................................... |
28 |
vi |
Sams Teach Yourself Visual C++ 6 in 21 Days |
Specifying the Control Tab Order .................................................................... |
30 |
Attaching Variables to Your Controls .................................................................... |
32 |
Attaching Functionality to the Controls ................................................................ |
33 |
Closing the Application .................................................................................... |
36 |
Showing the User’s Message............................................................................ |
37 |
Clearing the User’s Message ............................................................................ |
38 |
Disabling and Hiding the Message Controls.................................................... |
39 |
Running Another Application .......................................................................... |
42 |
Summary ................................................................................................................ |
44 |
Q&A ...................................................................................................................... |
44 |
Workshop .............................................................................................................. |
45 |
Quiz .................................................................................................................. |
45 |
Exercises .......................................................................................................... |
45 |
DAY 3 ALLOWING USER INTERACTION—INTEGRATING THE MOUSE AND KEYBOARD |
|
IN YOUR APPLICATION |
47 |
Understanding Mouse Events ................................................................................ |
48 |
Drawing with the Mouse .................................................................................. |
49 |
Improving the Drawing Program .................................................................... |
53 |
Adding the Finishing Touches.......................................................................... |
55 |
Capturing Keyboard Events .................................................................................. |
56 |
Changing the Drawing Cursor.......................................................................... |
57 |
Making the Change Stick ................................................................................ |
60 |
Summary ................................................................................................................ |
64 |
Q&A ...................................................................................................................... |
64 |
Workshop .............................................................................................................. |
65 |
Quiz .................................................................................................................. |
65 |
Exercises .......................................................................................................... |
65 |
DAY 4 WORKING WITH TIMERS |
67 |
Understanding Windows Timers............................................................................ |
68 |
Placing a Clock on Your Application .................................................................... |
68 |
Creating the Project and Application .............................................................. |
68 |
Adding the Timer IDs ...................................................................................... |
70 |
Starting the Clock Timer .................................................................................. |
71 |
Handling the Clock Timer Event...................................................................... |
72 |
Adding a Second Timer to Your Application ........................................................ |
74 |
Adding the Application Variables .................................................................... |
74 |
Starting and Stopping the Counting Timer ...................................................... |
75 |
Enabling the Stop Button ................................................................................ |
79 |
Summary ................................................................................................................ |
81 |
Contents |
vii |
Q&A ...................................................................................................................... |
81 |
Workshop .............................................................................................................. |
82 |
Quiz .................................................................................................................. |
82 |
Exercise ............................................................................................................ |
82 |
DAY 5 GETTING USER FEEDBACK—ADDING DIALOG BOXES TO YOUR APPLICATION |
83 |
Using Pre-existing (or System) Dialog Windows.................................................. |
84 |
Using Message Boxes ...................................................................................... |
84 |
Using Common Dialogs .................................................................................. |
90 |
Creating Your Own Dialog Windows .................................................................... |
93 |
Creating the Dialog Window ............................................................................ |
93 |
Using the Dialog in Your Application .............................................................. |
96 |
Summary .............................................................................................................. |
101 |
Q&A .................................................................................................................... |
101 |
Workshop ............................................................................................................ |
103 |
Quiz ................................................................................................................ |
103 |
Exercises ........................................................................................................ |
104 |
DAY 6 CREATING MENUS FOR YOUR APPLICATION |
105 |
Menus .................................................................................................................. |
106 |
Menu Styles .................................................................................................... |
106 |
Keyboard Shortcut–Enabling Menus ............................................................ |
106 |
Menu Standards and Conventions .................................................................. |
107 |
Designing Menus ................................................................................................ |
108 |
Creating a Menu .................................................................................................. |
108 |
Creating the Application ................................................................................ |
108 |
Adding and Customizing a Menu .................................................................. |
109 |
Attaching the Menu to Your Dialog Window ................................................ |
112 |
Attaching Functionality to Menu Entries ...................................................... |
112 |
Creating Pop-Up Menus ...................................................................................... |
116 |
Creating a Menu with Accelerators .................................................................... |
118 |
Summary .............................................................................................................. |
119 |
Q&A .................................................................................................................... |
119 |
Workshop ............................................................................................................ |
120 |
Quiz ................................................................................................................ |
120 |
Exercises ........................................................................................................ |
120 |
DAY 7 WORKING WITH TEXT AND FONTS |
121 |
Finding and Using Fonts...................................................................................... |
122 |
Listing the Available Fonts ............................................................................ |
122 |
Using a Font .................................................................................................. |
125 |
viii |
Sams Teach Yourself Visual C++ 6 in 21 Days |
Using Fonts .......................................................................................................... |
129 |
Creating the Application Shell ...................................................................... |
129 |
Building a List of Fonts.................................................................................. |
131 |
Setting the Font Sample Text ........................................................................ |
135 |
Selecting a Font to Display ............................................................................ |
136 |
Summary .............................................................................................................. |
139 |
Q&A .................................................................................................................... |
139 |
Workshop ............................................................................................................ |
140 |
Quiz ................................................................................................................ |
140 |
Exercises ........................................................................................................ |
140 |
WEEK 1 IN REVIEW |
143 |
WEEK 2 AT A GLANCE |
147 |
DAY 8 ADDING FLASH—INCORPORATING GRAPHICS, DRAWING, AND BITMAPS |
149 |
Understanding the Graphics Device Interface .................................................... |
150 |
Device Contexts.............................................................................................. |
150 |
Mapping Modes and Coordinate Systems...................................................... |
156 |
Creating a Graphics Application.......................................................................... |
157 |
Generating the Application Shell .................................................................. |
157 |
Adding the Graphics Capabilities .................................................................. |
163 |
Summary .............................................................................................................. |
177 |
Q&A .................................................................................................................... |
177 |
Workshop ............................................................................................................ |
177 |
Quiz ................................................................................................................ |
178 |
Exercises ........................................................................................................ |
178 |
DAY 9 ADDING ACTIVEX CONTROLS TO YOUR APPLICATION |
179 |
What Is an ActiveX Control? .............................................................................. |
180 |
ActiveX and the IDispatch Interface .............................................................. |
180 |
ActiveX Containers and Servers .................................................................... |
182 |
Adding an ActiveX Control to Your Project ........................................................ |
183 |
Registering the Control .................................................................................. |
183 |
Adding the Control to Your Dialog ................................................................ |
186 |
Using an ActiveX Control in Your Application .................................................. |
187 |
Interacting with the Control .......................................................................... |
187 |
Responding to Control Events........................................................................ |
193 |
Summary .............................................................................................................. |
196 |
Q&A .................................................................................................................... |
196 |
Workshop ............................................................................................................ |
197 |
Quiz ................................................................................................................ |
197 |
Exercise .......................................................................................................... |
197 |
Contents |
ix |
DAY 10 CREATING SINGLE DOCUMENT INTERFACE APPLICATIONS |
199 |
The Document/View Architecture ...................................................................... |
200 |
Creating an SDI Application................................................................................ |
202 |
Building the Application Shell ...................................................................... |
202 |
Creating a Line Class .................................................................................... |
203 |
Implementing the Document Functionality.................................................... |
205 |
Showing the User .......................................................................................... |
208 |
Saving and Loading the Drawing ........................................................................ |
213 |
Deleting the Current Drawing ........................................................................ |
214 |
Saving and Restoring the Drawing ................................................................ |
215 |
Interacting with the Menu.................................................................................... |
218 |
Adding Color to the CLine Class.................................................................... |
218 |
Adding Color to the Document ...................................................................... |
219 |
Modifying the Menu ...................................................................................... |
222 |
Summary .............................................................................................................. |
226 |
Q&A .................................................................................................................... |
227 |
Workshop ............................................................................................................ |
228 |
Quiz ................................................................................................................ |
228 |
Exercise .......................................................................................................... |
228 |
DAY 11 CREATING MULTIPLE DOCUMENT INTERFACE APPLICATIONS |
229 |
What Is an MDI Application?.............................................................................. |
229 |
Creating an MDI Drawing Program .................................................................... |
231 |
Building the Application Shell ...................................................................... |
231 |
Building the Drawing Functionality .............................................................. |
232 |
Adding Menu Handling Functionality .......................................................... |
233 |
Adding a Context Menu ...................................................................................... |
236 |
Summary .............................................................................................................. |
239 |
Q&A .................................................................................................................... |
239 |
Workshop ............................................................................................................ |
240 |
Quiz ................................................................................................................ |
240 |
Exercise .......................................................................................................... |
241 |
DAY 12 ADDING TOOLBARS AND STATUS BARS |
243 |
Toolbars, Status Bars, and Menus ...................................................................... |
244 |
Designing a Toolbar ............................................................................................ |
245 |
Creating a New Toolbar.................................................................................. |
246 |
Attaching the Toolbar to the Application Frame............................................ |
247 |
Controlling the Toolbar Visibility .................................................................. |
254 |
Adding a Combo Box to a Toolbar...................................................................... |
257 |
Editing the Project Resources ........................................................................ |
257 |
Creating the Toolbar Combo Box .................................................................. |
260 |
x |
Sams Teach Yourself Visual C++ 6 in 21 Days |
Handling the Toolbar Combo Box Events .................................................... |
267 |
Updating the Toolbar Combo Box ................................................................ |
268 |
Adding a New Status Bar Element ...................................................................... |
271 |
Adding a New Status Bar Pane ...................................................................... |
271 |
Setting a Status Bar Pane Text ...................................................................... |
273 |
Summary .............................................................................................................. |
275 |
Q&A .................................................................................................................... |
276 |
Workshop ............................................................................................................ |
277 |
Quiz ................................................................................................................ |
277 |
Exercises ........................................................................................................ |
277 |
DAY 13 SAVING AND RESTORING WORK—FILE ACCESS |
279 |
Serialization ........................................................................................................ |
279 |
The CArchive and CFile Classes .................................................................... |
280 |
The Serialize Function.................................................................................... |
281 |
Making Objects Serializable .......................................................................... |
281 |
Implementing a Serializable Class ...................................................................... |
283 |
Creating a Serialized Application .................................................................. |
284 |
Creating a Serializable Class.......................................................................... |
288 |
Building Support in the Document Class ...................................................... |
294 |
Adding Navigating and Editing Support in the View Class .......................... |
305 |
Summary .............................................................................................................. |
311 |
Q&A .................................................................................................................... |
311 |
Workshop ............................................................................................................ |
313 |
Quiz ................................................................................................................ |
313 |
Exercise .......................................................................................................... |
313 |
DAY 14 RETRIEVING DATA FROM AN ODBC DATABASE |
315 |
Database Access and ODBC................................................................................ |
316 |
The Open Database Connector (ODBC) Interface ........................................ |
316 |
The CRecordset Class.................................................................................... |
317 |
Creating a Database Application Using ODBC .................................................. |
322 |
Preparing the Database .................................................................................. |
322 |
Creating the Application Shell ...................................................................... |
324 |
Designing the Main Form .............................................................................. |
325 |
Adding New Records .................................................................................... |
331 |
Deleting Records ............................................................................................ |
334 |
Summary .............................................................................................................. |
335 |
Q&A .................................................................................................................... |
335 |
Workshop ............................................................................................................ |
336 |
Quiz ................................................................................................................ |
336 |
Exercise .......................................................................................................... |
336 |
Contents |
xi |
WEEK 2 IN REVIEW |
337 |
WEEK 3 AT A GLANCE |
341 |
DAY 15 UPDATING AND ADDING DATABASE RECORDS THROUGH ADO |
343 |
What Is ADO?...................................................................................................... |
344 |
ADO Objects .................................................................................................. |
345 |
Using the ADO ActiveX Control .................................................................. |
346 |
Importing the ADO DLL................................................................................ |
349 |
Connecting to a Database .............................................................................. |
350 |
Executing Commands and Retrieving Data .................................................. |
351 |
Navigating the Recordset .............................................................................. |
352 |
Accessing Field Values .................................................................................. |
353 |
Updating Records .......................................................................................... |
356 |
Adding and Deleting ...................................................................................... |
356 |
Closing the Recordset and Connection Objects .......................................... |
357 |
Building a Database Application Using ADO .................................................... |
358 |
Creating the Application Shell ...................................................................... |
358 |
Building a Custom Record Class .................................................................. |
361 |
Connecting and Retrieving Data .................................................................... |
365 |
Populating the Form ...................................................................................... |
367 |
Saving Updates .............................................................................................. |
370 |
Navigating the Record Set.............................................................................. |
371 |
Adding New Records .................................................................................... |
373 |
Deleting Records ............................................................................................ |
375 |
Summary .............................................................................................................. |
376 |
Q&A .................................................................................................................... |
377 |
Workshop ............................................................................................................ |
377 |
Quiz ................................................................................................................ |
377 |
Exercise .......................................................................................................... |
378 |
DAY 16 CREATING YOUR OWN CLASSES AND MODULES |
379 |
Designing Classes ................................................................................................ |
380 |
Encapsulation.................................................................................................. |
380 |
Inheritance ...................................................................................................... |
380 |
Visual C++ Class Types ................................................................................ |
381 |
Creating Library Modules.................................................................................... |
382 |
Using Library Modules........................................................................................ |
383 |
Creating the Library Module.......................................................................... |
383 |
Creating a Test Application ............................................................................ |
393 |
Updating the Library Module ........................................................................ |
398 |
xii |
Sams Teach Yourself Visual C++ 6 in 21 Days |
Summary .............................................................................................................. |
401 |
Q&A .................................................................................................................... |
402 |
Workshop ............................................................................................................ |
403 |
Quiz ................................................................................................................ |
403 |
Exercise .......................................................................................................... |
403 |
DAY 17 SHARING YOUR FUNCTIONALITY WITH OTHER APPLICATIONS—CREATING DLLS |
405 |
Why Create DLLs? .............................................................................................. |
406 |
Creating and Using DLLs .............................................................................. |
406 |
Designing DLLs ............................................................................................ |
409 |
Creating and Using an MFC Extension DLL...................................................... |
410 |
Creating the MFC Extension DLL ................................................................ |
410 |
Adapting the Test Application ........................................................................ |
413 |
Changing the DLL.......................................................................................... |
414 |
Creating and Using a Regular DLL .................................................................... |
416 |
Creating the Regular DLL.............................................................................. |
417 |
Adapting the Test Application ........................................................................ |
423 |
Summary .............................................................................................................. |
426 |
Q&A .................................................................................................................... |
427 |
Workshop ............................................................................................................ |
428 |
Quiz ................................................................................................................ |
428 |
Exercises ........................................................................................................ |
428 |
DAY 18 DOING MULTIPLE TASKS AT ONE TIME—MULTITASKING |
429 |
What Is Multitasking?.......................................................................................... |
430 |
Performing Multiple Tasks at One Time ........................................................ |
430 |
Idle Processing Threads.................................................................................. |
431 |
Spawning Independent Threads .................................................................... |
431 |
Building a Multitasking Application .................................................................. |
441 |
Creating a Framework .................................................................................... |
441 |
Designing Spinners ........................................................................................ |
443 |
Supporting the Spinners ................................................................................ |
449 |
Adding the OnIdle Tasks ................................................................................ |
455 |
Adding Independent Threads ........................................................................ |
460 |
Summary .............................................................................................................. |
468 |
Q&A .................................................................................................................... |
468 |
Workshop ............................................................................................................ |
471 |
Quiz ................................................................................................................ |
471 |
Exercises ........................................................................................................ |
471 |
Contents |
xiii |
DAY 19 BUILDING YOUR OWN WIDGETS—CREATING ACTIVEX CONTROLS |
473 |
What Is an ActiveX Control? .............................................................................. |
474 |
Properties ........................................................................................................ |
474 |
Methods .......................................................................................................... |
475 |
Events ............................................................................................................ |
476 |
Creating an ActiveX Control .............................................................................. |
476 |
Building the Control Shell.............................................................................. |
477 |
Modifying the CModArt Class ...................................................................... |
478 |
Adding Properties .......................................................................................... |
481 |
Designing and Building the Property Page .................................................... |
483 |
Adding Basic Control Functionality .............................................................. |
485 |
Adding Methods ............................................................................................ |
487 |
Adding Events ................................................................................................ |
489 |
Testing the Control ........................................................................................ |
491 |
Summary .............................................................................................................. |
493 |
Q&A .................................................................................................................... |
493 |
Workshop ............................................................................................................ |
494 |
Quiz ................................................................................................................ |
494 |
Exercises ........................................................................................................ |
494 |
DAY 20 INTERNET APPLICATIONS AND NETWORK COMMUNICATIONS |
495 |
How Do Network Communications Work? ........................................................ |
496 |
Sockets, Ports, and Addresses ........................................................................ |
497 |
Creating a Socket............................................................................................ |
498 |
Making a Connection .................................................................................... |
500 |
Sending and Receiving Messages .................................................................. |
501 |
Closing the Connection .................................................................................. |
503 |
Socket Events ................................................................................................ |
503 |
Detecting Errors.............................................................................................. |
504 |
Building a Networked Application ...................................................................... |
505 |
Creating the Application Shell ...................................................................... |
505 |
Window Layout and Startup Functionality .................................................... |
505 |
Inheriting from the CAsyncSocket Class ...................................................... |
509 |
Connecting the Application ............................................................................ |
511 |
Sending and Receiving .................................................................................. |
515 |
Ending the Connection .................................................................................. |
517 |
Summary .............................................................................................................. |
519 |
Q&A .................................................................................................................... |
519 |
Workshop ............................................................................................................ |
520 |
Quiz ................................................................................................................ |
520 |
Exercise .......................................................................................................... |
520 |
xiv |
Sams Teach Yourself Visual C++ 6 in 21 Days |
DAY 21 ADDING WEB BROWSING FUNCTIONALITY TO YOUR APPLICATIONS |
521 |
The Internet Explorer ActiveX Model ................................................................ |
522 |
The CHtmlView Class.......................................................................................... |
523 |
Navigating the Web ........................................................................................ |
523 |
Controlling the Browser ................................................................................ |
524 |
Getting the Browser Status ............................................................................ |
524 |
Building a Web-Browsing Application ................................................................ |
525 |
Creating the Application Shell ...................................................................... |
525 |
Adding Navigation Functionality .................................................................. |
526 |
Summary .............................................................................................................. |
535 |
Q&A .................................................................................................................... |
535 |
Workshop ............................................................................................................ |
536 |
Quiz ................................................................................................................ |
536 |
Exercises ........................................................................................................ |
536 |
WEEK 3 IN REVIEW |
537 |
APPENDIXES |
541 |
APPENDIX A C++ REVIEW |
541 |
Creating Your First Application .......................................................................... |
541 |
Helloworld.cpp .............................................................................................. |
543 |
The if Statement, Operators, and Polymorphism .......................................... |
549 |
Global and Local Variables ............................................................................ |
552 |
Pointers ................................................................................................................ |
554 |
References ...................................................................................................... |
557 |
Classes.................................................................................................................. |
559 |
Constructors and Destructors ........................................................................ |
564 |
Inheritance............................................................................................................ |
569 |
Summary .............................................................................................................. |
577 |
APPENDIX B ANSWERS |
579 |
Day 1.................................................................................................................... |
579 |
Quiz ................................................................................................................ |
579 |
Exercise .......................................................................................................... |
580 |
Day 2.................................................................................................................... |
580 |
Quiz ................................................................................................................ |
580 |
Exercises |
581 |
Day 3.................................................................................................................... |
585 |
Quiz ................................................................................................................ |
585 |
Exercises ........................................................................................................ |
585 |
Day 4.................................................................................................................... |
591 |
Quiz ................................................................................................................ |
591 |
Exercise .......................................................................................................... |
591 |
Day 5.................................................................................................................... |
593 |
Contents |
xv |
Quiz ................................................................................................................ |
593 |
Exercises ........................................................................................................ |
594 |
Day 6.................................................................................................................... |
596 |
Quiz ................................................................................................................ |
596 |
Exercises ........................................................................................................ |
596 |
Day 7.................................................................................................................... |
597 |
Quiz ................................................................................................................ |
597 |
Exercises ........................................................................................................ |
598 |
Day 8.................................................................................................................... |
602 |
Quiz ................................................................................................................ |
602 |
Exercises ........................................................................................................ |
602 |
Day 9.................................................................................................................... |
604 |
Quiz ................................................................................................................ |
604 |
Exercise .......................................................................................................... |
604 |
Day 10.................................................................................................................. |
605 |
Quiz ................................................................................................................ |
605 |
Exercise .......................................................................................................... |
606 |
Day 11.................................................................................................................. |
612 |
Quiz ................................................................................................................ |
612 |
Exercise .......................................................................................................... |
612 |
Day 12.................................................................................................................. |
614 |
Quiz ................................................................................................................ |
614 |
Exercises ........................................................................................................ |
615 |
Day 13.................................................................................................................. |
616 |
Quiz ................................................................................................................ |
616 |
Exercise .......................................................................................................... |
617 |
Day 14.................................................................................................................. |
620 |
Quiz ................................................................................................................ |
620 |
Exercise .......................................................................................................... |
621 |
Day 15.................................................................................................................. |
623 |
Quiz ................................................................................................................ |
623 |
Exercise .......................................................................................................... |
624 |
Day 16.................................................................................................................. |
625 |
Quiz ................................................................................................................ |
625 |
Exercises ........................................................................................................ |
625 |
Day 17.................................................................................................................. |
626 |
Quiz ................................................................................................................ |
626 |
Exercises ........................................................................................................ |
626 |
Day 18.................................................................................................................. |
628 |
Quiz ................................................................................................................ |
628 |
Exercises ........................................................................................................ |
628 |
Day 19.................................................................................................................. |
631 |
xvi |
Sams Teach Yourself Visual C++ 6 in 21 Days |
Quiz ................................................................................................................ |
631 |
Exercises ........................................................................................................ |
631 |
Day 20.................................................................................................................. |
632 |
Quiz ................................................................................................................ |
632 |
Exercises ........................................................................................................ |
633 |
Day 21.................................................................................................................. |
634 |
Quiz ................................................................................................................ |
634 |
Exercises ........................................................................................................ |
634 |
APPENDIX C PRINTING AND PRINT PREVIEWING |
637 |
Using the Framework’s Functionality ................................................................ |
637 |
Using Default Print Functionality .................................................................. |
638 |
Overriding OnPrint()...................................................................................... |
641 |
Using the Printer Device Context .................................................................. |
643 |
Maintaining the Aspect Ratio ........................................................................ |
645 |
Pagination and Orientation .................................................................................. |
647 |
Setting the Start and End Pages .................................................................... |
647 |
Using the Print Dialog Box ............................................................................ |
650 |
Using Portrait and Landscape Orientations.................................................... |
654 |
Adding GDI Objects with OnBeginPrinting() .............................................. |
654 |
Customizing Device Context Preparation ...................................................... |
656 |
Aborting the Print Job .................................................................................... |
657 |
Direct Printing Without the Framework .............................................................. |
657 |
Invoking the Print Dialog Box Directly ........................................................ |
657 |
Using StartDoc() and EndDoc() .................................................................. |
659 |
Using StartPage() and EndPage()................................................................ |
660 |
APPENDIX D UNDERSTANDING AND EXCEPTION HANDLING |
661 |
Using Exceptions ................................................................................................ |
661 |
Running Code and Catching the Errors ........................................................ |
661 |
Throwing Exceptions...................................................................................... |
666 |
Deleting Exceptions........................................................................................ |
668 |
MFC Exception Types ........................................................................................ |
668 |
Using the CException Base Class .................................................................. |
668 |
Using the Memory Exception ........................................................................ |
669 |
Using the Resource Exceptions...................................................................... |
670 |
Using the File and Archive Exceptions .......................................................... |
670 |
Using the Database Exceptions ...................................................................... |
672 |
Using OLE Exceptions .................................................................................. |
673 |
Using the Not Supported Exception .............................................................. |
674 |
Using the User Exception .............................................................................. |
674 |
Generating Your Own Custom Exception Classes ........................................ |
675 |
Contents |
xvii |
APPENDIX E USING THE DEBUGGER AND PROFILER |
677 |
Creating Debugging and Browse Information .................................................... |
677 |
Using Debug and Release Modes .................................................................. |
678 |
Setting Debug Options and Levels ................................................................ |
679 |
Creating and Using Browse Information ...................................................... |
681 |
Using Remote and Just-in-Time Debugging .................................................. |
683 |
Tracing and Single Stepping................................................................................ |
685 |
Using the TRACE Macro ................................................................................ |
685 |
Using the ASSERT and VERIFY macros.......................................................... |
687 |
Using Breakpoints and Single Stepping the Program.................................... |
689 |
Using Edit and Continue ................................................................................ |
692 |
Watching Program Variables .......................................................................... |
692 |
Other Debugger Windows .............................................................................. |
694 |
Additional Debugging Tools................................................................................ |
694 |
Using Spy++ .................................................................................................. |
695 |
Process Viewer................................................................................................ |
697 |
The OLE/COM Object Viewer ...................................................................... |
697 |
The MFC Tracer ............................................................................................ |
698 |
APPENDIX F USING MFC’S HELPER CLASSES |
699 |
Using the Collection Classes .............................................................................. |
699 |
Using the Array Classes ................................................................................ |
700 |
Using the List Classes .................................................................................... |
702 |
Using the Map Classes .................................................................................. |
704 |
Creating Custom Collection Classes .............................................................. |
707 |
Using the Coordinate-Handling Classes.............................................................. |
710 |
Using the CPoint Class .................................................................................. |
710 |
Using the CRect Class.................................................................................... |
712 |
Using the CSize Class .................................................................................... |
717 |
Using the Time-Handling Classes ...................................................................... |
718 |
Using the COleDateTime Class...................................................................... |
719 |
Using the COleDateTimeSpan Class ............................................................ |
722 |
Using the String Manipulation Class .................................................................. |
724 |
Using the CString Class ................................................................................ |
724 |
String Manipulation........................................................................................ |
727 |
Searching Strings............................................................................................ |
727 |
Formatting Text for Display .......................................................................... |
728 |
INDEX |
731 |