Build real-world applications as Horton Join the discussion @ p2p.wrox.com Wrox Programmer to Programmer™ you dive into C++ development Ivor Horton’s Beginning By following author Ivor Horton’s accessible tutorial approach and detailed examples you can quickly become an effective C++ V programmer. Thoroughly updated for the 2010 release, this book introduces you to the latest development environment and teaches you how to build real-world applications using Visual C++. With i this book by your side, you are well on your way to writing applications s in both versions of C++ and becoming a successful C++ programmer. wrox.com u Ivor Horton’s Beginning Visual C++ 2010: (cid:129) T eaches the essentials of C++ programming using both of the Programmer a C++ language technologies supported by Visual C++ 2010 Forums (cid:129) S hares techniques for finding errors in C++ programs and explains l Join our Programmer to general debugging principles Programmer forums to ask and answer programming (cid:129) D iscusses the structure and essential elements that are present in questions about this book, C every Windows® application join discussions on the hottest topics in the industry, (cid:129) D emonstrates how to develop native Windows applications using and connect with fellow + the Microsoft Foundation Classes programmers from around the world. (cid:129) G uides you through designing and creating substantial Windows + Code Downloads applications in both C++ and C++/CLI Take advantage of free code (cid:129) F eatures numerous working examples and exercises that help build ® samples from this book, as programming skills well as code samples from Ivor Horton’s 2 hundreds of other books, all Ivor Horton is one of the preeminent authors of tutorials on the Java, C and C++ ready to use. Beginning programming languages. He is widely known for his unique tutorial style, which is readily accessible to both novice and experienced programmers. Horton is also Read More 0 a systems consultant in private practice. He previously taught programming for ++ more than 25 years. Find articles, ebooks, sample Visual C 2010 1 chapters, and tables of contents ® for hundreds of books, and Wrox Beginning guides are crafted to make learning programming languages more reference resources on 0 and technologies easier than you think, providing a structured, tutorial format programming topics that matter that will guide you through all the techniques involved. to you. Ivor Horton $54.99 USA Programming / C++ Development $65.99 CAN Related Wrox Books Beginning ASP.NET 4: in C# and VB ISBN: 978-0-470-50221-1 Programmer to Programmer™ This introductory book offers helpful examples in a step-by-step format and has code examples written in both C# and Visual Basic. With this book, a web site example takes you through the processes of building basic ASP.NET web pages, adding features with pre-built server controls, designing consistent pages, displaying data, and more. Get more out of Beginning Visual C# 2010 ISBN: 978-0-470-50226-6 Using this book, you will first cover the fundamentals such as variables, flow control, and object-oriented programming and gradually build your skills for web and Windows programming, Windows forms, and data access. Step-by-step directions walk you through processes and invite you to “Try it Out” at every stage. By the end, you’ll be able to write useful programming code following the steps wrox.com you’ve learned in this thorough, practical book. If you’ve always wanted to master Visual C# programming, this book is the perfect one-stop resource. Professional ASP.NET 4: in C# and VB ISBN: 978-0-470-50220-4 Written by three highly recognized and regarded ASP.NET experts, this book provides all-encompassing coverage on ASP.NET 4 and offers a unique approach of featuring examples in both C# and VB. After a fast-paced refresher on essentials such as server controls, the book delves into expert coverage of all the latest capabilities of ASP.NET 4. You’ll learn site navigation, personalization, membership, role management, security, and more. Interact Join the Community Professional C++ Take an active role online by participating in our Sign up for our free monthly newsletter at ISBN: 978-0-7645-7484-9 This code-intensive, practical guide teaches all facets of C++ development, including effective application design, testing, and debugging. P2P forums @ p2p.wrox.com newsletter.wrox.com You’ll learn simple, powerful techniques used by C++ professionals, little-known features that will make your life easier, and reusable coding patterns that will bring your basic C++ skills to the professional level. Wrox Online Library Browse Professional C# 4 and .NET 4 ISBN: 978-0-470-50225-9 Hundreds of our books are available online Ready for more Wrox? We have books and After a quick refresher on C# basics, the author dream team moves on to provide you with details of language and framework through Books24x7.com e-books available on .NET, SQL Server, Java, features including LINQ, LINQ to SQL, LINQ to XML, WCF, WPF, Workflow, and Generics. Coverage also spans ASP.NET programming with C#, working in Visual Studio 2010 with C#, and more. With this book, you’ll quickly get up to date on all the newest XML, Visual Basic, C#/ C++, and much more! capabilities of C# 4. Wrox Blox Professional Visual Basic 2010 and .NET 4 Download short informational pieces and code ISBN: 978-0-470-50224-2 to keep you up to date and out of trouble! If you’ve already covered the basics and want to dive deep into VB and .NET topics that professional programmers use most, this is your guide. You’ll explore all the new features of Visual Basic 2010 as well as all the essential functions that you need, including .NET features such as LINQ to SQL, LINQ to XML, WCF, and more. Plus, you’ll examine exception handling and debugging, Visual Studio features, and ASP.NET web programming. Professional Visual Studio 2010 ISBN: 978-0-470-54865-3 Written by an author team of veteran programmers and developers, this book gets you quickly up to speed on what you can expect from Visual Studio 2010. Packed with helpful examples, this comprehensive guide examines the features of Visual Studio 2010 and walks you through every facet of the Integrated Development Environment (IDE), from common tasks and functions to its powerful tools. Contact Us. Visual Basic 2010 Programmer’s Reference We always like to get feedback from our readers. Have a book idea? ISBN: 978-0-470-49983-2 Need community support? Let us know by e-mailing [email protected] Visual Basic 2010 Programmer’s Reference is a language tutorial and a reference guide to the 2010 release of Visual Basic. The tutorial provides basic material suitable for beginners but also includes in-depth content for more advanced developers IVOR HORTON’S BEGINNING VISUAL C++® 2010 INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxiii CHAPTER 1 Programming with Visual C++ 2010 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1 CHAPTER 2 Data, Variables, and Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 CHAPTER 3 Decisions and Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .121 CHAPTER 4 Arrays, Strings, and Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 CHAPTER 5 Introducing Structure into Your Programs . . . . . . . . . . . . . . . . . . . . . . . . 251 CHAPTER 6 More about Program Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .295 CHAPTER 7 Defi ning Your Own Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .353 CHAPTER 8 More on Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .435 CHAPTER 9 Class Inheritance and Virtual Functions . . . . . . . . . . . . . . . . . . . . . . . . .549 CHAPTER 10 The Standard Template Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .645 CHAPTER 11 Debugging Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .755 CHAPTER 12 Windows Programming Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .807 CHAPTER 13 Programming for Multiple Cores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .843 CHAPTER 14 Windows Programming with the Microsoft Foundation Classes . . . . .875 CHAPTER 15 Working with Menus and Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .903 CHAPTER 16 Drawing in a Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .945 CHAPTER 17 Creating the Document and Improving the View . . . . . . . . . . . . . . . . .1009 CHAPTER 18 Working with Dialogs and Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1059 CHAPTER 19 Storing and Printing Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1123 CHAPTER 20 Writing Your Own DLLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1175 INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1193 ffffiirrss..iinndddd ii 33//1177//1100 66::5544::4488 PPMM ffffiirrss..iinndddd iiii 33//1177//1100 66::5544::4499 PPMM IVOR HORTON’S BEGINNING Visual C++® 2010 ffffiirrss..iinndddd iiiiii 33//1177//1100 66::5544::4499 PPMM ffffiirrss..iinndddd iivv 33//1177//1100 66::5544::5500 PPMM IVOR HORTON’S BEGINNING Visual C++® 2010 Ivor Horton ffffiirrss..iinndddd vv 33//1177//1100 66::5544::5500 PPMM Ivor Horton’s Beginning Visual C++® 2010 Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2010 by Ivor Horton Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-50088-0 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 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 Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, 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 specifi cally disclaim all warranties, including without limitation warranties of fi tness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained 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 Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites 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 (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Library of Congress Control Number: 2010921242 Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Wrox Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affi liates, in the United States and other countries, and may not be used without written permission. Visual C++ is a registered trademark of Microsoft Corporation 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. ffffiirrss..iinndddd vvii 33//1177//1100 66::5544::5522 PPMM This book is for Edward Gilbey, who arrived in September 2009 and has been a joy to have around ever since. ffffiirrss..iinndddd vviiii 33//1177//1100 66::5544::5533 PPMM ffffiirrss..iinndddd vviiiiii 33//1177//1100 66::5544::5533 PPMM