beginning visual c++ 2005

1.2K 328 0
beginning visual c++ 2005

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

www.it-ebooks.info Ivor Horton’s Beginning Visual C++ ® 2005 Ivor Horton 01_571974 ffirs.qxp 1/20/06 11:22 PM Page iii www.it-ebooks.info 01_571974 ffirs.qxp 1/20/06 11:22 PM Page ii www.it-ebooks.info Ivor Horton’s Beginning Visual C++ ® 2005 01_571974 ffirs.qxp 1/20/06 11:22 PM Page i www.it-ebooks.info 01_571974 ffirs.qxp 1/20/06 11:22 PM Page ii www.it-ebooks.info Ivor Horton’s Beginning Visual C++ ® 2005 Ivor Horton 01_571974 ffirs.qxp 1/20/06 11:22 PM Page iii www.it-ebooks.info Ivor Horton’s Beginning Visual C++ ® 2005 Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2006 by Ivor Horton Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN-13: 978-0-7645-7197-8 ISBN-10: 0-7645-7197-4 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 1B/QY/QS/QW/IN Library of Congress Cataloging-in-Publication Data: Horton, Ivor. Ivor Horton’s Beginning Visual C++ 2005 / Ivor Horton. p. cm. Includes index. ISBN-13: 978-0-7645-7197-8 (paper/website) ISBN-10: 0-7645-7197-4 (paper/website) 1. C++ (Computer program language) 2. Microsoft Visual C++. I. Title: Beginning Visual C++ 2005. II. Title. QA76.73.C15I6694 2006 005.13’3—dc22 2005032051 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, or online at http://www.wiley.com/go/permissions. LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CRE- ATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CON- TAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FUR- THER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ. For general information on our other products and services please contact our Customer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. Visual C++ is a registered trademark of Microsoft Cor- poration in the United States and/or other countries. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. 01_571974 ffirs.qxp 1/20/06 11:22 PM Page iv www.it-ebooks.info Credits Executive Editor Bob Elliott Senior Development Editor Kevin Kent Development Editor Howard Jones Technical Editor John Mueller Production Editor Pamela Hanley Copy Editor Susan Hobbs Editorial Manager Mary Beth Wakefield Production Manager Tim Tate Vice President and Executive Group Publisher Richard Swadley Vice President and Executive Publisher Joseph B. Wikert Project Coordinator Ryan Steffen Graphics and Production Specialists Brian Drumm Lauren Goddard Brooke Graczyk Denny Hager Joyce Haughey Jennifer Heleine Stephanie D. Jumper Barry Offringa Alicia South Erin Zeltner Quality Control Technicians Laura Albert John Greenough Leeann Harney Proofreading TECHBOOKS Production Services Indexing Infodex Indexing Services Inc. 01_571974 ffirs.qxp 1/20/06 11:22 PM Page v www.it-ebooks.info 01_571974 ffirs.qxp 1/20/06 11:22 PM Page vi www.it-ebooks.info About the Author Ivor Horton graduated as a mathematician and was lured into information technology by promises of great rewards for very little work. In spite of the reality being usually a great deal of work for relatively modest rewards, he has continued to work with computers to the present day. He has been engaged at various times in programming, systems design, consultancy, and the management of the implementa- tion of projects of considerable complexity. Horton has many years of experience in the design and implementation of computer systems applied to engineering design and to manufacturing operations in a variety of industries. He also has considerable experience in developing occasionally useful applications in a wide variety of programming languages, and of teaching primarily scientists and engineers to do likewise. He has written books on programming for more than 10 years; his currently published works include tutorials on C, C++, and Java. At the pre- sent time, when he is not writing programming books or providing advice to others, he spends his time fishing, travelling, and trying to speak better French. 01_571974 ffirs.qxp 1/20/06 11:22 PM Page ix www.it-ebooks.info [...]... I could not have done it without her www.it-ebooks.info www.it-ebooks.info Contents Acknowledgments xi Chapter 1: Programming with Visual C++ 2005 The NET Framework The Common Language Runtime (CLR) Writing C++ Applications Learning Windows Programming Learning C++ The C++ Standards Console Applications Windows Programming Concepts What Is the Integrated Development Environment? Components of the System... Global Variables Static Variables Namespaces 88 88 91 91 94 95 Declaring a Namespace Multiple Namespaces 96 98 C++/ CLI Programming 99 C++/ CLI Specific: Fundamental Data Types C++/ CLI Output to the Command Line C++/ CLI Specific — Formatting the Output C++/ CLI Input from the Keyboard Using safe_cast C++/ CLI Enumerations 99 104 104 107 108 109 Specifying a Type for Enumeration Constants Specifying Values for... Program Dealing with Errors 13 19 23 Setting Options in Visual C++ 2005 Creating and Executing Windows Applications 27 28 Creating an MFC Application Building and Executing the MFC Application 28 30 Creating a Windows Forms Application Summary 31 35 xiii www.it-ebooks.info Contents Chapter 2: Data, Variables, and Calculations The Structure of a C++ Program 37 38 Program Comments The #include Directive... Console Programs 46 47 49 49 50 Defining Variables 51 Naming Variables 51 Keywords in C++ 52 Declaring Variables Initial Values for Variables 52 53 Fundamental Data Types 54 Integer Variables Character Data Types Integer Type Modifiers The Boolean Type Floating-Point Types 54 55 56 57 57 Fundamental Types in ISO/ANSI C++ 58 Literals Defining Synonyms for Data Types Variables with Specific Sets of Values... Incomplete Class Definitions 499 501 503 504 Pure Virtual Functions Abstract Classes Indirect Base Classes Virtual Destructors 505 505 508 511 Casting Between Class Types Nested Classes C++/ CLI Programming 516 516 520 Inheritance in C++/ CLI Classes Interface Classes Defining Interface Classes Classes and Assemblies 520 526 527 531 Visibility Specifiers for Classes and Interfaces Access Specifiers for Class... Drawing in a Window 707 Basics of Drawing in a Window 707 The Window Client Area The Windows Graphical Device Interface What Is a Device Context? Mapping Modes 708 709 709 709 The Drawing Mechanism in Visual C++ The View Class in Your Application 711 711 The OnDraw() Member Function 711 The CDC Class 712 Displaying Graphics Drawing in Color 713 717 Drawing Graphics in Practice Programming the Mouse 721... a Block of Statements 132 What Is a Loop? Variations on the for Loop 132 135 Using the continue Statement Floating-Point Loop Counters 139 143 The while Loop The do-while Loop Nested Loops 143 146 147 C++/ CLI Programming 150 The for each Loop 153 Summary Exercises 156 157 Chapter 4: Arrays, Strings, and Pointers Handling Multiple Data Values of the Same Type Arrays Declaring Arrays Initializing Arrays... delete Operators Allocating Memory Dynamically for Arrays Dynamic Allocation of Multidimensional Arrays Using References 192 193 194 196 197 What Is a Reference? Declaring and Initializing References C++/ CLI Programming 197 197 198 Tracking Handles 199 Declaring Tracking Handles 199 CLR Arrays 200 Sorting One-Dimensional Arrays Searching One-Dimensional Arrays Multidimensional Arrays Arrays of Arrays... Cast Iron Rule for Returning Addresses Returning a Reference 256 258 A Teflon-Coated Rule: Returning References Static Variables in a Function 260 260 Recursive Function Calls 262 Using Recursion 264 C++/ CLI Programming 265 Functions Accepting a Variable Number of Arguments Arguments to main() Summary Exercises 266 267 268 269 Chapter 6: More about Program Structure Pointers to Functions 271 271 Declaring... Expression 294 295 xviii www.it-ebooks.info Contents Getting the Value of a Term Analyzing a Number Putting the Program Together Extending the Program Extracting a Substring Running the Modified Program C++/ CLI Programming 298 299 302 304 305 307 308 Understanding Generic Functions Defining Generic Functions Using Generic Functions 309 309 310 A Calculator Program for the CLR Removing Spaces from the . Beginning Visual C++ ® 2005 01_571974 ffirs.qxp 1/20/06 11:22 PM Page i www.it-ebooks.info 01_571974 ffirs.qxp 1/20/06 11:22 PM Page ii www.it-ebooks.info Ivor Horton’s Beginning Visual C++ ® 2005 Ivor. (paper/website) 1. C++ (Computer program language) 2. Microsoft Visual C++. I. Title: Beginning Visual C++ 2005. II. Title. QA76.73.C15I6694 2006 005.13’3—dc22 20050 32051 No part of this publication may be reproduced,. 1: Programming with Visual C++ 2005 1 The .NET Framework 2 The Common Language Runtime (CLR) 2 Writing C++ Applications 3 Learning Windows Programming 4 Learning C++ 5 The C++ Standards 5 Console

Ngày đăng: 05/05/2014, 13:17

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan