ffirs.indd ii
17/09/12 6:32 PM
IVOR HORTON’S
BEGINNING VISUAL C ++® 2012
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxv
CHAPTER 1
Programming with Visual C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
CHAPTER 2
Data, Variables, and Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
CHAPTER 3
Decisions and Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
CHAPTER 4
Arrays, Strings, and Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
CHAPTER 5
Introducing Structure into Your Programs . . . . . . . . . . . . . . . . . . . . . . . . 189
CHAPTER 6
More about Program Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
CHAPTER 7
Defining Your Own Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
CHAPTER 8
More on Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
CHAPTER 9
Class Inheritance and Virtual Functions . . . . . . . . . . . . . . . . . . . . . . . . . 441
CHAPTER 10
The Standard Template Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
CHAPTER 11
Windows Programming Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 601
CHAPTER 12
Windows Programming
with the Microsoft Foundation Classes (MFC) . . . . . . . . . . . . . . . . . . . . 635
CHAPTER 13
Working with Menus and Toolbars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
CHAPTER 14
Drawing in a Window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685
CHAPTER 15
Improving the View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 739
CHAPTER 16
Working with Dialogs and Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 769
CHAPTER 17
Storing and Printing Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 815
CHAPTER 18
Programming Windows 8 Apps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 905
ffirs.indd i
17/09/12 6:32 PM
ffirs.indd ii
17/09/12 6:32 PM
IVOR HORTON’S
BEGINNING
®
Visual C ++ 2012
ffirs.indd iii
17/09/12 6:32 PM
Related Wrox Books
Beginning ASP.NET 4.5
ISBN: 978-1-118-31180-6
Featuring a user-friendly, step-by-step format, the book guides you through customizing the IDE, building
a Planet Wrox website example, working with files and web forms, designing web pages, displaying and
updating data, creating tables, and much more. With this resource in hand, you will be completely at ease
learning ASP.NET 4.5.
Beginning Visual C# 2012
ISBN 978-1-118-31441-8
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 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 C++, 2nd Edition
ISBN: 978-0-470-93244-5
With this no-nonsense book, you will learn to conquer the latest version of the C++ language: C++11. The
authors share real-world examples, decipher little-known features of C++, and reveal the significant changes
to C++ that accompany the latest release. Ultimately, you’ll discover programming methodologies, reusable
design patterns, and good programming style that will increase the quality of your code and improve your
programming efficiency.
Professional C# 2012 and .NET 4.5
ISBN 978-1-118-31442-5
After a quick refresher on C# basics, the author dream team moves on to provide you with details of language
and framework 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 2012 with C#, and more.
Professional Visual Basic 2012 and .NET 4.5
ISBN: 978-1-118-31445-6
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 2012. Packed with helpful examples, this comprehensive guide
examines the features of Visual Studio 2012, and walks you through every facet of the Integrated Development
Environment (IDE), from common tasks and functions to its powerful tools.
Professional Visual Studio 2012
ISBN: 978-1-118-33770-7
This book is what you need to get up and running quickly on Visual Studio 2012. Written by a Microsoft
Visual C# MVP, it guides you through the integrated development environment (IDE), showing you how to
maximize each of the tools and features.
Visual Basic 2012 Programmer’s Reference
ISBN: 978-1-118-31407-4
Visual Basic 2012 is packed with powerful features and this book will help you master them all. You’ll gain
a solid understanding of essential Visual Basic topics and begin applying the information to perform a host
of important development tasks. The tutorials inside are filled with code examples and the best methods for
using them to write your own programs.
Related Wrox Books
Beginning ASP.NET 4.5
ISBN: 978-1-118-31180-6
Featuring a user-friendly, step-by-step format, the book guides you through customizing the IDE, building
a Planet Wrox website example, working with files and web forms, designing web pages, displaying and
updating data, creating tables, and much more. With this resource in hand, you will be completely at ease
learning ASP.NET 4.5.
Beginning Visual C# 2012
ISBN 978-1-118-31441-8
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 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 C++, 2nd Edition
ISBN: 978-0-470-93244-5
With this no-nonsense book, you will learn to conquer the latest version of the C++ language: C++11. The
authors share real-world examples, decipher little-known features of C++, and reveal the significant changes
to C++ that accompany the latest release. Ultimately, you’ll discover programming methodologies, reusable
design patterns, and good programming style that will increase the quality of your code and improve your
programming efficiency.
Professional C# 2012 and .NET 4.5
ISBN 978-1-118-31442-5
After a quick refresher on C# basics, the author dream team moves on to provide you with details of language
and framework 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 2012 with C#, and more.
Professional Visual Basic 2012 and .NET 4.5
ISBN: 978-1-118-31445-6
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 2012. Packed with helpful examples, this comprehensive guide
examines the features of Visual Studio 2012, and walks you through every facet of the Integrated Development
Environment (IDE), from common tasks and functions to its powerful tools.
Professional Visual Studio 2012
ISBN: 978-1-118-33770-7
This book is what you need to get up and running quickly on Visual Studio 2012. Written by a Microsoft
Visual C# MVP, it guides you through the integrated development environment (IDE), showing you how to
maximize each of the tools and features.
Visual Basic 2012 Programmer’s Reference
ISBN: 978-1-118-31407-4
Visual Basic 2012 is packed with powerful features and this book will help you master them all. You’ll gain
a solid understanding of essential Visual Basic topics and begin applying the information to perform a host
of important development tasks. The tutorials inside are filled with code examples and the best methods for
using them to write your own programs.