Programming Windows®, Sixth Edition

Total Page:16

File Type:pdf, Size:1020Kb

Programming Windows®, Sixth Edition Programming Windows ®, Sixth Edition Charles Petzold PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2013 by Charles Petzold 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. Library of Congress Control Number: 2012955549 ISBN: 978-0-7356-7176-8 Printed and bound in the United States of America. Second Printing 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 Editor: Devon Musgrave Developmental Editor: Devon Musgrave Project Editor: Devon Musgrave Editorial Production: Waypoint Press Technical Reviewer: Marc Young Indexer: Christina Yeager Cover: Twist Creative • Seattle and Joel Panchot [M] [2013-02-08] Contents at a glance Introduction xvii PART I ELEMENTALS CHAPTER 1 Markup and Code 3 CHAPTER 2 XAML Syntax 31 CHAPTER 3 Basic Event Handling 69 CHAPTER 4 Presentation with Panels 97 CHAPTER 5 Control Interaction 139 CHAPTER 6 WinRT and MVVM 193 CHAPTER 7 Asynchronicity 221 CHAPTER 8 App Bars and Popups 261 CHAPTER 9 Animation 329 CHAPTER 10 Transforms 377 CHAPTER 11 The Three Templates 449 CHAPTER 12 Pages and Navigation 539 PART II SPECIALTIES CHAPTER 13 Touch, Etc. 615 CHAPTER 14 Bitmaps 683 CHAPTER 15 Going Native 779 CHAPTER 16 Rich Text 845 CHAPTER 17 Share and Print 893 CHAPTER 18 Sensors and GPS 953 CHAPTER 19 Pen (Also Known as Stylus) 1013 Index 1057 This page intentionally left blank Table of Contents Introduction xvii PART I ELEMENTALS Chapter 1 Markup and Code 3 The First Project . 3 Graphical Greetings . 9 Variations in Text . .13 Media As Well . .22 The Code Alternatives . .23 Images in Code . .27 Not Even a Page . .29 Chapter 2 XAML Syntax 31 The Gradient Brush in Code . .31 Property Element Syntax . .34 Content Properties . .37 The TextBlock Content Property . .41 Sharing Brushes (and Other Resources) . .43 Resources Are Shared . .47 Exploring Vector Graphics . .48 What do you think of this book? We want to hear from you! Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you. To participate in a brief online survey, please visit: microsoft.com/learning/booksurvey vii Stretching with Viewbox. .58 Styles . .60 A Taste of Data Binding . .66 Chapter 3 Basic Event Handling 69 The Tapped Event . .69 Routed Event Handling . .72 Overriding the Handled Setting . .78 Input, Alignment, and Backgrounds . .80 Size and Orientation Changes . .83 Bindings to Run? . .87 Timers and Animation . .89 Chapter 4 Presentation with Panels 97 The Border Element . .97 Rectangle and Ellipse . .101 The StackPanel . .103 Horizontal Stacks . .106 WhatSize with Bindings (and a Converter) . .108 The ScrollViewer Solution . .112 Layout Weirdness or Normalcy?. .118 Making an E-Book . .119 Fancier StackPanel Items . .122 Deriving from UserControl . .124 Creating Windows Runtime Libraries . .127 The Wrap Alternative . .130 The Canvas and Attached Properties . .132 The Z-Index . .136 Canvas Weirdness . .137 viii Contents Chapter 5 Control Interaction 139 The Control Difference . .139 The Slider for Ranges . .141 The Grid . .146 Orientation and Aspect Ratios . .152 Slider and the Formatted String Converter . .154 Tooltips and Conversions . .154 Sketching with Sliders. .157 The Varieties of Button Experience . .159 Defi ning Dependency Properties . .167 RadioButton Tags . .177 Keyboard Input and TextBox . .184 Touch and Thumb . .187 Chapter 6 WinRT and MVVM 193 MVVM (Brief and Simplifi ed) . .193 Data Binding Notifi cations . .194 A View Model for ColorScroll . .196 Syntactic Shortcuts . .201 The DataContext Property . .204 Bindings and TextBox . .206 Buttons and MVVM . .212 The DelegateCommand Class . .213 Chapter 7 Asynchronicity 221 Threads and the User Interface . .221 Working with MessageDialog . .222 Callbacks as Lambda Functions . .228 The Amazing await Operator . .229 Cancelling an Asynchronous Operation . .231 Contents ix Approaches to File I/O . .233 Application Local Storage . .234 File Pickers . .234 Bulk Access . .235 File Pickers and File I/O . .235 Handling Exceptions . ..
Recommended publications
  • Understanding the Attack Surface and Attack Resilience of Project Spartan’S (Edge) New Edgehtml Rendering Engine
    Understanding the Attack Surface and Attack Resilience of Project Spartan’s (Edge) New EdgeHTML Rendering Engine Mark Vincent Yason IBM X-Force Advanced Research yasonm[at]ph[dot]ibm[dot]com @MarkYason [v2] © 2015 IBM Corporation Agenda . Overview . Attack Surface . Exploit Mitigations . Conclusion © 2015 IBM Corporation 2 Notes . Detailed whitepaper is available . All information is based on Microsoft Edge running on 64-bit Windows 10 build 10240 (edgehtml.dll version 11.0.10240.16384) © 2015 IBM Corporation 3 Overview © 2015 IBM Corporation Overview > EdgeHTML Rendering Engine © 2015 IBM Corporation 5 Overview > EdgeHTML Attack Surface Map & Exploit Mitigations © 2015 IBM Corporation 6 Overview > Initial Recon: MSHTML and EdgeHTML . EdgeHTML is forked from Trident (MSHTML) . Problem: Quickly identify major code changes (features/functionalities) from MSHTML to EdgeHTML . One option: Diff class names and namespaces © 2015 IBM Corporation 7 Overview > Initial Recon: Diffing MSHTML and EdgeHTML (Method) © 2015 IBM Corporation 8 Overview > Initial Recon: Diffing MSHTML and EdgeHTML (Examples) . Suggests change in image support: . Suggests new DOM object types: © 2015 IBM Corporation 9 Overview > Initial Recon: Diffing MSHTML and EdgeHTML (Examples) . Suggests ported code from another rendering engine (Blink) for Web Audio support: © 2015 IBM Corporation 10 Overview > Initial Recon: Diffing MSHTML and EdgeHTML (Notes) . Further analysis needed –Renamed class/namespace results into a new namespace plus a deleted namespace . Requires availability
    [Show full text]
  • Create Mobile Apps with HTML5, Javascript and Visual Studio
    Create mobile apps with HTML5, JavaScript and Visual Studio DevExtreme Mobile is a single page application (SPA) framework for your next Windows Phone, iOS and Android application, ready for online publication or packaged as a store-ready native app using Apache Cordova (PhoneGap). With DevExtreme, you can target today’s most popular mobile devices with a single codebase and create interactive solutions that will amaze. Get started today… ・ Leverage your existing Visual Studio expertise. ・ Build a real app, not just a web page. ・ Deliver a native UI and experience on all supported devices. ・ Use over 30 built-in touch optimized widgets. Learn more and download your free trial devexpress.com/mobile All trademarks or registered trademarks are property of their respective owners. Untitled-4 1 10/2/13 11:58 AM APPLICATIONS & DEVELOPMENT SPECIAL GOVERNMENT ISSUE INSIDE Choose a Cloud Network for Government-Compliant magazine Applications Geo-Visualization of SPECIAL GOVERNMENT ISSUE & DEVELOPMENT SPECIAL GOVERNMENT ISSUE APPLICATIONS Government Data Sources Harness Open Data with CKAN, OData and Windows Azure Engage Communities with Open311 THE DIGITAL GOVERNMENT ISSUE Inside the tools, technologies and APIs that are changing the way government interacts with citizens. PLUS SPECIAL GOVERNMENT ISSUE APPLICATIONS & DEVELOPMENT SPECIAL GOVERNMENT ISSUE & DEVELOPMENT SPECIAL GOVERNMENT ISSUE APPLICATIONS Enhance Services with Windows Phone 8 Wallet and NFC Leverage Web Assets as Data Sources for Apps APPLICATIONS & DEVELOPMENT SPECIAL GOVERNMENT ISSUE ISSUE GOVERNMENT SPECIAL DEVELOPMENT & APPLICATIONS Untitled-1 1 10/4/13 11:40 AM CONTENTS OCTOBER 2013/SPECIAL GOVERNMENT ISSUE OCTOBER 2013/SPECIAL GOVERNMENT ISSUE magazine FEATURES MOHAMMAD AL-SABT Editorial Director/[email protected] Geo-Visualization of Government KENT SHARKEY Site Manager Data Sources MICHAEL DESMOND Editor in Chief/[email protected] Malcolm Hyson ..........................................
    [Show full text]
  • Microsoft Patches Were Evaluated up to and Including CVE-2020-1587
    Honeywell Commercial Security 2700 Blankenbaker Pkwy, Suite 150 Louisville, KY 40299 Phone: 1-502-297-5700 Phone: 1-800-323-4576 Fax: 1-502-666-7021 https://www.security.honeywell.com The purpose of this document is to identify the patches that have been delivered by Microsoft® which have been tested against Pro-Watch. All the below listed patches have been tested against the current shipping version of Pro-Watch with no adverse effects being observed. Microsoft Patches were evaluated up to and including CVE-2020-1587. Patches not listed below are not applicable to a Pro-Watch system. 2020 – Microsoft® Patches Tested with Pro-Watch CVE-2020-1587 Windows Ancillary Function Driver for WinSock Elevation of Privilege Vulnerability CVE-2020-1584 Windows dnsrslvr.dll Elevation of Privilege Vulnerability CVE-2020-1579 Windows Function Discovery SSDP Provider Elevation of Privilege Vulnerability CVE-2020-1578 Windows Kernel Information Disclosure Vulnerability CVE-2020-1577 DirectWrite Information Disclosure Vulnerability CVE-2020-1570 Scripting Engine Memory Corruption Vulnerability CVE-2020-1569 Microsoft Edge Memory Corruption Vulnerability CVE-2020-1568 Microsoft Edge PDF Remote Code Execution Vulnerability CVE-2020-1567 MSHTML Engine Remote Code Execution Vulnerability CVE-2020-1566 Windows Kernel Elevation of Privilege Vulnerability CVE-2020-1565 Windows Elevation of Privilege Vulnerability CVE-2020-1564 Jet Database Engine Remote Code Execution Vulnerability CVE-2020-1562 Microsoft Graphics Components Remote Code Execution Vulnerability
    [Show full text]
  • Exam Ref 70-482: Advanced Windows Store App Development Using HTML5 and Javascript
    Exam Ref 70-482: Advanced Windows Store App Development Using HTML5 and JavaScript Roberto Brunetti Vanni Boncinelli Copyright © 2013 by Roberto Brunetti and Vanni Boncinelli 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-7680-0 1 2 3 4 5 6 7 8 9 QG 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 respec- tive owners. The example companies, organizations, products, domain names, email ad- dresses, 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 con- tained 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.
    [Show full text]
  • (RUNTIME) a Salud Total
    Windows 7 Developer Guide Published October 2008 For more information, press only: Rapid Response Team Waggener Edstrom Worldwide (503) 443-7070 [email protected] Downloaded from www.WillyDev.NET The information contained in this document represents the current view of Microsoft Corp. on the issues discussed as of the date of publication. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication. This guide is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY. Complying with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form, by any means (electronic, mechanical, photocopying, recording or otherwise), or for any purpose, without the express written permission of Microsoft. Microsoft may have patents, patent applications, trademarks, copyrights or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. Unless otherwise noted, the example companies, organizations, products, domain names, e-mail addresses, logos, people, places and events depicted herein are fictitious, and no association with any real company, organization, product, domain name, e-mail address, logo, person, place or event is intended or should be inferred.
    [Show full text]
  • 1.1.2 MIT Backbonejs.Org File Bootstrap Apache
    Resource name License License reference Usage Type backbone-1.1.2 MIT backbonejs.org File bootstrap Apache 2.0 http://getbootstrap.com/javascript/ File bootstrap-datetimepicker-v2.0.1 Apache 2.0 https://github.com/Eonasdan/bootstrap-datetimepicker/blob/v2.0.1/LICENSE File cache.js MIT https://github.com/monsur/jscache FIle Common.Logging.Core.dll Apache 2.0 http://netcommon.sourceforge.net/license.html Dynamic Library Common.Logging.dll Apache 2.0 http://netcommon.sourceforge.net/license.html Dynamic Library DocumentFormat.OpenXml.dll Apache 2.0 https://github.com/OfficeDev/Open-XML-SDK/blob/master/LICENSE.txt Dynamic Library enquire.js MIT http://wicky.nillia.ms/enquire.js File globalize MIT http://github.com/jquery/globalize File handlebars MIT https://github.com/wycats/handlebars.js/blob/master/LICENSE File HTML5 Sortable MIT License http://farhadi.ir/projects/html5sortable/ File hu.js MIT https://github.com/Canop/hu.js File ICSharpCode.SharpZipLib.dll GPL with exceptions http://icsharpcode.github.io/SharpZipLib/ Dynamic Library icudt34.dll ICU License http://www-306.ibm.com/software/globalization/icu/index.jsp Dynamic Library icuin34.dll ICU License http://www-306.ibm.com/software/globalization/icu/index.jsp Dynamic Library icuuc34.dll ICU License http://www-306.ibm.com/software/globalization/icu/index.jsp Dynamic Library indexedDBshim MIT https://github.com/axemclion/IndexedDBShim File interact.js MIT https://raw.github.com/taye/interact.js/master/LICENSE File interact.js MIT https://raw.githubusercontent.com/taye/interact.js/master/LICENSE
    [Show full text]
  • New Visual Studio 2013 Diagnostic Tools
    New Visual Studio 2013 Diagnostic Tools --- Overview In this lab, you will learn about some of the new diagnostic tools that were introduced with Visual Studio 2012 updates, as well as the new diagnostic tools introduced in Visual Studio 2013. You will also be introduced to the enhanced asynchronous debugging features found in Visual Studio 2013. Objectives In this hands-on lab, you will learn how to do the following: - Use the Performance and Diagnostics Hub - Use the UI Responsiveness Tools for JavaScript and XAML Windows Store applications - Use the Energy Consumption Tool - Analyze JavaScript Memory Usage - Create and Analyze Managed Memory Dumps - Use the enhanced asynchronous debugging features in Visual Studio 2013 Prerequisites The following are required to complete this hands-on lab: - Windows 8.1 - Microsoft Visual Studio 2013 (with Update 2 RC applied) Notes Estimated time to complete this lab: 60 minutes. Note: You can log into the virtual machine with user name “User” and password “P2ssw0rd”. Note: This lab may make references to code and other assets that are needed to complete the exercises. You can find these assets on the desktop in a folder named TechEd 2014. Within that folder, you will find additional folders that match the name of the lab you are working on. Exercise 1: Introduction to Performance and Diagnostics Hub In this exercise, you will you will learn about the new Performance and Diagnostics Hub in Visual Studio 2013. The new hub brings together existing tools into one location, and makes it easier to see what tools are available for the current project based on the current language, application type, or platform.
    [Show full text]
  • Open Source Components
    Open Source Components Resource Name License License Reference Usage Type ace.js BSD https://github.com/ajaxorg/ace/blob/master/LICENSE backbone-1.1.2 MIT backbonejs.org File bootstrap Apache 2.0 http://getbootstrap.com/javascript/ File bootstrap-datetimepicker-v2.0.1 Apache 2.0 https://github.com/Eonasdan/bootstrap-datetimepicker/blob/v2.0.1/LICENSE File cache.js MIT https://github.com/monsur/jscache FIle Common.Logging.Core.dll Apache 2.0 http://netcommon.sourceforge.net/license.html Dynamic Library Common.Logging.dll Apache 2.0 http://netcommon.sourceforge.net/license.html Dynamic Library DeployR Apache 2.0 https://deployr.revolutionanalytics.com/license/ DrillDown.js MIT http://code.highcharts.com/modules/drilldown.js File DocumentFormat.OpenXml.dll Apache 2.0 https://github.com/OfficeDev/Open-XML-SDK/blob/master/LICENSE.txt Dynamic Library enquire.js MIT http://wicky.nillia.ms/enquire.js File globalize MIT http://github.com/jquery/globalize File handlebars MIT https://github.com/wycats/handlebars.js/blob/master/LICENSE File HTML5 Sortable MIT License http://farhadi.ir/projects/html5sortable/ File hu.js MIT https://github.com/Canop/hu.js File ICSharpCode.SharpZipLib.dll GPL with exceptions http://icsharpcode.github.io/SharpZipLib/ Dynamic Library icudt34.dll ICU License http://www-306.ibm.com/software/globalization/icu/index.jsp Dynamic Library icuin34.dll ICU License http://www-306.ibm.com/software/globalization/icu/index.jsp Dynamic Library icuuc34.dll ICU License http://www-306.ibm.com/software/globalization/icu/index.jsp Dynamic
    [Show full text]
  • Windows Tweaks Guide
    Windows Tweaks Guide For By Windows Geeks Team Introduction .......................................................................................................................................... 5 Important Notes on This Guide........................................................................................................... 5 Usage Instruction.................................................................................................................................. 5 No Warranty .......................................................................................................................................... 5 Hosting, Distribution & Translation ................................................................................................... 6 Tweaks for Windows XP ...................................................................................................................... 6 Before You Begin Tweaking XP ................................................................................................. 6 Tweaks for Startup ..................................................................................................................... 8 Tweaks for Shutdown .............................................................................................................. 10 Tweaks for Mouse .................................................................................................................... 10 Tweaks for Start Menu ............................................................................................................
    [Show full text]
  • Sample Content from Programming Microsoft Windows Forms
    Programming Microsoft® Windows® Forms Charles Petzold To learn more about this book, visit Microsoft Learning at http://www.microsoft.com/MSPress/books/7824.aspx 9780735621534 Publication Date: November 2005 A04T621535.fm Page v Friday, September 30, 2005 10:18 AM Table of Contents Introduction. xi Your Background and Needs . .xi Organization of This Book . xii System Requirements. xiii Prerelease Software . xiii Technology Updates. .xiii Code Samples . .xiv Support for This Book . xiv Questions and Comments . .xiv The Author’s Web Site . .xiv Special Thanks. xv 1 Creating Applications . 1 Orientation . 1 Programming Tools . 2 The Docs . 3 Development . 5 The Littlest Programs . 5 Visual Studio Projects. 6 References . 8 From Console to Windows . 9 Fixing the Flaws . 11 Events and Event Handlers . 13 Inheriting from Form . 16 Properties and Events in Visual Studio . 19 Children of the Form . 22 Subclassing Controls . 26 Device-Independent Coding . 29 Assembly Information . 33 Dialog Boxes . 34 DLLs . .44 What do you think of this book? Microsoft is interested in hearing your feedback about this publication so we can continually improve our books and learning resources for you. To participate in a brief We want to hear from you! online survey, please visit: www.microsoft.com/learning/booksurvey/ v A04T621535.fm Page vi Friday, September 30, 2005 10:18 AM vi Table of Contents 2 The Control Cornucopia . 47 Controls in General . 48 Parents and Children . 48 Visibility and Response . 50 Location and Size . 51 Fonts and Color . 52 Keeping Track of Controls . 53 Image Lists . 54 ToolTips . 54 Static (and Not Quite so Static) Controls .
    [Show full text]
  • Directx 11 Extended to the Implementation of Compute Shader
    DirectX 1 DirectX About the Tutorial Microsoft DirectX is considered as a collection of application programming interfaces (APIs) for managing tasks related to multimedia, especially with respect to game programming and video which are designed on Microsoft platforms. Direct3D which is a renowned product of DirectX is also used by other software applications for visualization and graphics tasks such as CAD/CAM engineering. Audience This tutorial has been prepared for developers and programmers in multimedia industry who are interested to pursue their career in DirectX. Prerequisites Before proceeding with this tutorial, it is expected that reader should have knowledge of multimedia, graphics and game programming basics. This includes mathematical foundations as well. Copyright & Disclaimer Copyright 2019 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected]
    [Show full text]
  • NET Technology Guide for Business Applications // 1
    .NET Technology Guide for Business Applications Professional Cesar de la Torre David Carmona Visit us today at microsoftpressstore.com • Hundreds of titles available – Books, eBooks, and online resources from industry experts • Free U.S. shipping • eBooks in multiple formats – Read on your computer, tablet, mobile device, or e-reader • Print & eBook Best Value Packs • eBook Deal of the Week – Save up to 60% on featured titles • Newsletter and special offers – Be the first to hear about new releases, specials, and more • Register your book – Get additional benefits Hear about it first. Get the latest news from Microsoft Press sent to your inbox. • New and upcoming books • Special offers • Free eBooks • How-to articles Sign up today at MicrosoftPressStore.com/Newsletters Wait, there’s more... Find more great content and resources in the Microsoft Press Guided Tours app. The Microsoft Press Guided Tours app provides insightful tours by Microsoft Press authors of new and evolving Microsoft technologies. • Share text, code, illustrations, videos, and links with peers and friends • Create and manage highlights and notes • View resources and download code samples • Tag resources as favorites or to read later • Watch explanatory videos • Copy complete code listings and scripts Download from Windows Store Free ebooks From technical overviews to drilldowns on special topics, get free ebooks from Microsoft Press at: www.microsoftvirtualacademy.com/ebooks Download your free ebooks in PDF, EPUB, and/or Mobi for Kindle formats. Look for other great resources at Microsoft Virtual Academy, where you can learn new skills and help advance your career with free Microsoft training delivered by experts.
    [Show full text]