Build Windows 8 Apps with Microsoft Visual C++ Step by Step
Total Page:16
File Type:pdf, Size:1020Kb
Build Windows 8 Apps with Microsoft Visual C++ Step by Step Luca Regnicoli Paolo Pialorsi Roberto Brunetti Copyright © 2013 by Luca Regnicoli, Paolo Pialorsi, Roberto Brunetti. All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher. ISBN: 978-0-7356-6723-5 1 2 3 4 5 6 7 8 9 LSI 8 7 6 5 4 3 Printed and bound in the United States of America. Microsoft Press books are available through booksellers and distributors worldwide. If you need support related to this book, email Microsoft Press Book Support at [email protected]. Please tell us what you think of this book at http://www.microsoft.com/learning/booksurvey. Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty/ Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners. The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book. Acquisitions and Developmental Editor: Russell Jones Production Editor: Christopher Hearse Editorial Production: Zyg Group, LLC Technical Reviewer: John Mueller Copyeditor: Zyg Group, LLC Indexer: Zyg Group, LLC Cover Design: Twist Creative • Seattle Cover Composition: Zyg Group, LLC Illustrator: Rebecca Demarest This book is dedicated to Barbara. —ROBERTO BRUNETTI This book is dedicated to my parents. Thanks! —PAOLO PIALORSI This book is dedicated to my mother, Vanna, the strongest woman I have ever known. —LUCA REGNICOLI Contents at a Glance Introduction xi CHapTER 1 Introduction to Windows Store apps 1 CHapTER 2 Windows 8 user interface style 29 CHapTER 3 My first Windows 8 app 65 CHapTER 4 Application life-cycle management 103 Chapter 5 Introduction to the Windows Runtime 139 Chapter 6 Windows runtime APIs 161 CHapTER 7 Enhance the user experience 193 CHapTER 8 asynchronous patterns 235 CHapTER 9 rethinking the UI for Windows 8 apps 265 CHapTER 10 Architecting a Windows 8 app 307 Index 343 Contents Introduction .....................................................xi Chapter 1 Introduction to Windows Store apps 1 The Windows 8 experience .........................................1 Charms bar and app bars ..........................................8 Windows Runtime ................................................13 Badges, live tiles, toasts, and lock screen ............................15 Background tasks ................................................19 Contracts and extensions .........................................22 Visual Studio 2012 and Windows 8 Simulator ........................24 Summary. .27 Quick reference ..................................................28 Chapter 2 Windows 8 user interface style 29 Influences .......................................................29 Bauhaus style in the Windows 8 UI .................................36 Enhance the functionality and the content, not the container ....36 Industrialize the software and user interface, and create projects, not products .......................................37 Use clear typography .......................................37 Take advantage of the grid system. .37 Prefer photos over drawings .................................38 Select few and contrasting colors .............................38 Strive for international language and employ essential iconography ...............................................39 Characteristics of a Windows 8 app .................................39 Silhouette .................................................39 Full screen .................................................46 Edges .....................................................48 Comfort and touch .........................................50 vii Semantic Zoom .............................................55 Animations ................................................58 Different form factors .......................................58 Snapped and fill views .......................................60 Summary. .63 Quick reference ..................................................63 Chapter 3 My first Windows 8 app 65 Software installation ..............................................65 Windows Store project templates ..................................66 UI elements .....................................................75 Search functionality ..............................................87 Summary. .101 Quick reference .................................................102 Chapter 4 Application life-cycle management 103 Application manifest ............................................104 Application package .............................................107 Windows Store ..................................................110 Launching. .114 Activating ......................................................122 Suspending .....................................................125 Resuming ......................................................130 Summary. .137 Quick reference .................................................137 Chapter 5 Introduction to the Windows Runtime 139 What is WinRT? .................................................139 WinRT under the hood. .144 WinRT design requirements ......................................148 Creating a WinMD library ........................................149 viii Contents WinRT app registration ..........................................157 Summary ......................................................159 Quick reference .................................................160 Chapter 6 Windows Runtime APIs 161 Using pickers ...................................................161 Webcam .......................................................169 Sharing contracts ...............................................176 Summary. .191 Quick reference .................................................191 Chapter 7 Enhance the user experience 193 Draw an application using Visual Studio 2012 .......................193 Create the layout of a Windows 8 application .......................197 Customize the appearance of controls .............................220 Summary. .234 Quick reference .................................................234 Chapter 8 Asynchronous patterns 235 Asynchronous calls with the Parallel Patterns Library in C++ ..........235 Writing asynchronous methods ...................................241 Waiting for an event in an asynchronous way .......................248 Cancelling asynchronous operations ...............................251 Tracking operation progress ......................................253 Synchronization with multiple asynchronous calls. 260 Synchronizing execution context. .262 Summary. .264 Quick reference .................................................264 Contents ix Chapter 9 Rethinking the UI for Windows 8 apps 265 Using Windows 8 UI-specific controls ..............................265 Designing flexible layouts ........................................286 Using tiles and toasts ............................................294 Summary. .305 Quick reference .................................................305 Chapter 10 Architecting a Windows 8 app 307 Applications architecture in general ...............................308 Architectures for Windows 8 apps .................................310 Implementing the data layer. .311 Implementing the communication layer using a SOAP service ........314 Implementing the communication layer using an OData service ......318 Consuming data from a Windows 8 app ...........................323 Implementing an app storage/cache ..............................330 SOAP security infrastructure ......................................333 OData security infrastructure .....................................338 Summary. .342 Quick reference ................................................342 Index 343 x Contents Introduction indows 8 is Microsoft’s newest operating system, intended to let developers Wfluent in various programming languages—such as C++, C#, or JavaScript— leverage its powerful infrastructure to build applications using a brand-new library called the Windows Runtime API. This book provides an organized walk-through of the features, APIs, and user experi- ence in Windows 8. The content is introductory—it discusses each component from a theoretical viewpoint interspersed with basic but effective code samples, which you can follow to get a jump-start in developing for the Windows 8 platform. The book provides coverage of almost all the main Windows 8 aspects and fea- tures, and it offers essential guidance in learning them using the classic Step by Step approach. In addition to its coverage of core Windows 8 features using C++, the book dis- cusses some related aspects, such as Windows Communication Foundation (WCF) Data Services, Open Data Protocol (OData), ADO.NET Entity Framework, and applications architecture. Beyond the explanatory content, each chapter includes a rich set of step- by-step examples,