Mastering Windows 8 C++ App Development A practical guide to developing Windows Store apps with C++ and XAML Pavel Yosifovich BIRMINGHAM - MUMBAI Mastering Windows 8 C++ App Development Copyright © 2013 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: April 2013 Production Reference: 1080413 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-84969-502-2 www.packtpub.com Cover Image by Neha Rajappan ([email protected]) Credits Author Project Coordinator Pavel Yosifovich Anurag Banerjee Reviewers Proofreader Daniel Biesiada Linda Morris Eric van Feggelen Alon Fliess Indexer Hemangini Bari James P. McNellis Yusak Setiawan Graphics Aditi Gajjar Acquisition Editor Erol Staveley Production Coordinator Prachali Bhiwandkar Lead Technical Editor Sweny Sukumaran Cover Work Prachali Bhiwandkar Technical Editors Prasad Dalvi Worrell Lewis About the Author Pavel Yosifovich is the CTO of CodeValue (http://www.codevalue.net), a software development, consulting, and training company, based in Israel. He is also the author of Windows Presentation Foundation 4.5 Cookbook, Packt Publishing, 2012. He writes, develops, consults, and trains developers on various software development topics, from Windows internals, to .NET enterprise systems, and almost everything in between. He's a Microsoft MVP and a frequent speaker at national events. In the past, he co-founded the startup company Quiksee that was acquired by Google in September 2010. Writing a book takes tremendous effort, and would not have been possible without the support and encouragement of my family—my wife Idit and my kids Daniel, Amit, and Yoav. I know it was hard watching me sit at my computer and write for hours at a time. Thank you for your patience! About the Reviewers Daniel Biesiada is a software professional with 13 years of experience as a developer, consultant, and most recently as a technology evangelist at Microsoft in Poland. In 2012, he left corporate ranks to pursue individual challenges related to cloud and mobile opportunities as a consultant and architect of the software solutions. He speaks on local events in Poland, as well as internationally and works actively with communities to develop new generations of smart and future-oriented developers. With his startup uShine – IT Consulting he realized several Windows 8 projects for customers in media and education industries including iOS to Windows 8 ports and creating unique intellectual properties for Windows 8 and the modern Web. He was helping local software leaders at Microsoft for 5 years with executive advisory related to Microsoft software development technologies. In the last two years of work at Microsoft, he helped launch cloud products in local markets (Windows Azure) and to fill Windows Store with high-quality applications targeting Windows 8. He is the co-author of the book Windows Azure Platforma Cloud Computing dla programistów, APN Promise that introduced Windows Azure to Polish developers in the local (Polish) market. He can be reached by e-mail at [email protected]. Eric van Feggelen is a passionate and experienced software consultant who delivers high-quality solutions using the latest technology available. He has about 15 years of experience as a developer and has been widely interested in information technology his entire life. In the past few years he worked for major corporations such as Microsoft and Avanade and continues to serve the Microsoft Enterprise space as a private contractor for his own company. For more information on Eric check out his personal website http://appbyfex.com/. Alon Fliess is the Chief Architect and founder of CodeValue. CodeValue is the home of software experts. CodeValue builds software tools, foundations, and products for the software industry. CodeValue offers mentoring, consulting, and project development services. Alon got his BSc degree in Electrical and Computer Engineering from The Technion, Israel Institute of Technology. He is an expert in many Microsoft technologies, including Windows client and server programming using C#/C++/.NET, Windows Azure Cloud Computing, ALM with TFS, and Windows internals. Microsoft has recognized his expertise and community activities and granted him two awards: Microsoft Regional Director (MRD) and a VC++ MVP. He has deep knowledge and understanding of Windows and Windows internals, he is the co-author of Windows 7 Microsoft Training Program, Microsoft Press as well as the co-author of Introducing Windows 7 for Developers, Microsoft Press. He delivers courses and lectures in many seminars and conferences around the world such as TechEd Europe, TechEd USA, NDC, and in Israel. He is a senior Software Architect, who deals with vast and complex projects. Many thanks to Pavel and Anurag Banerjee for giving me the opportunity to take part in the creation of this book. Yusak Setiawan (@yoesak) works at Tigabelas Technology, the company that he founded 3 years ago. He has 10 years' experience of coding in different languages, especially in C/C++, C#, Objective C, and also JavaScript. His company, and he, now focus on making Windows 8 apps, and also support Microsoft Indonesia by training, and mentoring, young developers and corporates in Indonesia in making good Windows 8 apps. He also worked with some Redmond guys before Visual Studio 2012 was released. You can find his work in Windows 8 Store (AndaTube, Alkitab, and MathBoard). I would like to thank Sweny Sukumaran and Anurag Banerjee, for giving me the challenge of reviewing this book, also my wife Nidya Chatelya and my newborn baby Edmond Grant; they both are my inspiration. www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub. com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why Subscribe? • Fully searchable across every book published by Packt • Copy and paste, print and bookmark content • On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Introduction to Windows 8 Apps 7 Introducing Windows 8 7 Touch everywhere 8 The Start (Home) screen 8 The AppBar 9 The Charms bar 10 Desktop apps versus Store apps 11 The Windows Runtime 12 Language projections 14 Building the user interface 15 Creating your first Store application 15 Closing an application 19 Application deployment 20 Where did int.ToString come from? 21 Project structure 22 Summary 25 Chapter 2: COM and C++ for Windows 8 Store Apps 27 Welcome to C++11 28 New features in C++11 28 nullptr 28 auto 29 Lambdas 30 Smart pointers 33 Conclusion 36 COM and WinRT 37 The IUnknown interface 41 IInspectable interface 42 Creating a WinRT object 43
Description: