1. Trang chủ
  2. » Công Nghệ Thông Tin

Programming Windows pptx

579 162 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 579
Dung lượng 9,26 MB

Nội dung

Charles Petzold Windows ® Programming SIXTH EDITION Writing Windows 8 Apps With C# and XAML Release Preview eBook PUBLISHED BY Microsoft Press A Division of Microsoft Corporation One Microsoft Way Redmond, Washington 98052-6399 Copyright © 2012 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. ISBN: 978-0-7356-7176-8 This document supports a preliminary release of a software product that may be changed substantially prior to final commercial release. This document is provided for informational purposes only and Microsoft makes no warranties, either express or implied, in this document. Information in this document, including URL and other Internet website references, is subject to change without notice. The entire risk of the use or the results from the use of this document remains with the user. Unless otherwise noted, the companies, organizations, products, domain names, e-mail addresses, logos, people, places, and events depicted in examples herein are fictitious. No association with any real company, organization, product, domain name, e-mail address, logo, person, place, or event is intended or should be inferred. 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 or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. 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. 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, Developmental, and Project Editor: Devon Musgrave Technical Reviewer: Marc Young Cover: Twist Creative • Seattle Do wn l oa d f ro m W ow! e B oo k < ww w .w owe bo o k. com > Introduction 9 The Versions of Windows 8 9 The Focus of This Book 10 The Approach 12 My Setup 13 The Programming Windows Heritage 13 Behind the Scenes 16 Errata & Book Support 17 We Want to Hear from You 17 Stay in Touch 17 Chapter 1: Markup and Code 18 The First Project 18 Graphical Greetings 24 Variations in Text 28 Media As Well 36 The Code Alternatives 37 Images in Code 41 Not Even a Page 43 Chapter 2: XAML Syntax 45 The Gradient Brush in Code 45 Property Element Syntax 48 Content Properties 51 The TextBlock Content Property 55 Sharing Brushes (and Other Resources) 57 Resources Are Shared 61 A Bit of Vector Graphics 62 Stretching with Viewbox 71 Styles 74 A Taste of Data Binding 80 3 Chapter 3: Basic Event Handling 83 The Tapped Event 83 Routed Event Handling 86 Overriding the Handled Setting 92 Input, Alignment, and Backgrounds 93 Size and Orientation Changes 97 Bindings to Run? 101 Timers and Animation 103 Chapter 4: The Border Element 111 The Border Element 111 Rectangle and Ellipse 115 The StackPanel 117 Horizontal Stacks 121 WhatSize with Bindings (and a Converter) 124 The ScrollViewer Solution 128 Layout Weirdness or Normalcy? 134 Making an E-Book 135 Fancier StackPanel Items 138 Deriving from UserControl 141 Creating Windows Runtime Libraries 143 The Wrap Alternative 146 The Canvas and Attached Properties 148 The Z-Index 153 Canvas Weirdness 153 Chapter 5: Control Interaction 155 The Control Difference 155 The Slider for Ranges 157 The Grid 161 Orientation and Aspect Ratios 168 Slider and the Formatted String Converter 171 4 Tooltips and Conversions 171 Sketching with Sliders 174 The Varieties of Button Experience 176 Defining Dependency Properties 184 RadioButton Tags 194 Keyboard Input and TextBox 200 Touch and Thumb 204 Chapter 6: WinRT and MVVM 211 MVVM (Brief and Simplified) 211 Data Binding Notifications 212 A View Model for ColorScroll 214 Syntactic Shortcuts 219 The DataContext Property 222 Bindings and TextBox 224 Buttons and MVVM 230 The DelegateCommand Class 231 Chapter 7: Building an Application 238 Commands, Options, and Settings 238 The Segoe UI Symbol Font 240 The Application Bar 246 Popups and Dialogs 248 Windows Runtime File I/O 251 Await and Async 258 Calling Your Own Async Methods 260 Controls for XamlCruncher 263 Application Settings and Isolated Storage 278 The XamlCruncher Page 282 Parsing the XAML 286 XAML Files In and Out 288 The Settings Dialog 292 5 Beyond the Windows Runtime 298 Chapter 8: Animation 299 The Windows.UI.Xaml.Media.Animation Namespace 299 Animation Basics 300 Animation Variation Appreciation 303 Other Double Animations 310 Animating Attached Properties 317 The Easing Functions 320 All-XAML Animations 329 Animating Custom Classes 333 Key Frame Animations 337 The Object Animation 341 Predefined Animations and Transitions 343 Chapter 9: Transforms 347 A Brief Overview 347 Rotation (Manual and Animated) 350 Visual Feedback 356 Translation 358 Transform Groups 361 The Scale Transform 366 Building an Analog Clock 370 Skew 375 Making an Entrance 378 Transform Mathematics 379 The CompositeTransform 386 Geometry Transforms 389 Brush Transforms 391 Dude, Where’s My Element? 395 Projection Transforms 398 Deriving a Matrix3D 405 6 Chapter 13: Touch, Etc. 416 A Pointer Roadmap 417 A First Dab at Finger Painting 420 Capturing the Pointer 423 Editing with a Popup Menu 431 Pressure Sensitivity 435 How Do I Save My Drawings? 438 A Touch Piano 439 Manipulation, Fingers, and Elements 444 Working with Inertia 452 An XYSlider Control 456 Centered Scaling and Rotation 462 Single-Finger Rotation 466 Chapter 14: Bitmaps 473 Pixel Bits 474 Transparency and Premultiplied Alphas 480 A Radial Gradient Brush 485 Loading and Saving Image Files 493 In Progress 503 Completed 503 Chapter 15: Printing 504 Basic Printing 504 Printable and Unprintable Margins 511 The Pagination Process 515 Custom Printing Properties 522 Printing a Monthly Planner 527 Printing a Range of Pages 537 Where to Do the Big Jobs? 548 7 Chapter 16: Going Native 549 An Introduction to P/Invoke 549 Some Help 555 Time Zone Information 555 A Windows Runtime Component Wrapper for DirectX 577 About the Author 578 8 Introduction This book—the 6 th edition of Programming Windows—is a guide to programming applications that run under Microsoft Windows 8. At the time of this writing (August 1, 2012), Windows 8 is not yet complete and neither is this book. What you are reading right now is a preview ebook version of the book. This preview ebook is based on the Release Preview of Windows 8 (build 8400), which was released on May 31, 2012. Microsoft has announced that Windows 8 will be released for general availability on October 26, 2012. Microsoft Press and I are targeting the release of the final version of this book for mid-November. To use this book, you’ll need to download and install the Windows 8 Release Preview, as well as Microsoft Visual Studio Express 2012 RC for Windows 8. Both downloads are accessible from the Windows 8 developer portal: http://msdn.microsoft.com/windows/apps To install Visual Studio, follow the “Download the tools and SDK” link on that page. The Versions of Windows 8 For the most part, Windows 8 is intended to run on the same class of personal computers as Windows 7, which are machines built around the 32-bit or 64-bit Intel x86 microprocessor family. When Windows 8 is released later this year, it will be available in a regular edition called simply Windows 8 and also a Windows 8 Pro edition with additional features that appeal to tech enthusiasts and professionals. Both Windows 8 and Windows 8 Pro will run two types of programs:  Desktop applications  New Windows 8 applications Desktop applications are traditional Windows programs that currently run under Windows 7 and that interact with the operating system through the Windows application programming interface, known familiarly as the Win32 API. To run these desktop applications, Windows 8 includes a familiar Windows desktop screen. The new Windows 8 applications represent a radical break with traditional Windows. The programs generally run in a full-screen mode—although two programs can share the screen in a “snap” mode—and many of these programs will probably be optimized for touch and tablet use. These applications will be purchasable and installable only from an application store run by Microsoft. 9 A design paradigm is sometimes associated with these new Windows 8 applications. Somewhat inspired by signage in urban environments, this design paradigm emphasizes content over program “chrome” and is characterized by the use of unadorned fonts, clean open styling, a tile-based interface, and transitional animations. In addition to the versions of Windows 8 that run on x86 processors, there will also be a version of Windows 8 that runs on ARM processors, most likely in low-cost tablets. This version of Windows 8 will be called Windows RT, and it will come preinstalled on these machines. Aside from some preinstalled desktop applications, Windows RT will run new Windows 8 applications only. Many developers were first introduced to the Windows 8 design principles with Windows Phone 7, so it’s interesting to see how Microsoft’s thinking concerning large and small computers has evolved. In years gone by, Microsoft attempted to adapt the design of the traditional Windows desktop to smaller devices such as hand-held computers and phones. Now a user-interface design for the phone is being moved up to tablets and the desktop. One important characteristic of this new environment is an emphasis on multitouch, which has dramatically changed the relationship between human and computer. In fact, the term "multitouch" is now outmoded because virtually all new touch devices respond to multiple fingers. The simple word "touch" is now sufficient. Part of the new programming interface for Windows 8 applications treats touch, mouse, and pen input in a unified manner so that applications are automatically usable with all three input devices. The Focus of This Book This book focuses exclusively on writing new Windows 8 applications. Plenty of other books already exist for writing Win32 desktop applications, including the 5 th edition of Programming Windows. I’ll occasionally make reference to the Win32 API and desktop applications, but this book is really all about writing new Windows 8 applications. For writing these applications, a new object-oriented API has been introduced called the Windows Runtime or WinRT (not to be confused with the version of Windows 8 that runs on ARM processors, called Windows RT). Internally, the Windows Runtime is based on COM (Component Object Model) with interfaces exposed through metadata files with the extension .winmd located in the /Windows/System32/WinMetadata directory. Externally, it is very object-oriented. From the application programmer’s perspective, the Windows Runtime resembles Silverlight, although internally it is not a managed API. For Silverlight programmers, perhaps the most immediate difference involves namespace names: the Silverlight namespaces beginning with System.Windows have been replaced with namespaces beginning with Windows.UI.Xaml. Most Windows 8 applications will be built from both code and markup, either the industry-standard HyperText Markup Language (HTML) or Microsoft’s eXtensible Application Markup Language (XAML). 10 [...]... using using using using using using using System; System.Collections.Generic; System.IO; System.Linq; Windows. Foundation; Windows. Foundation.Collections; Windows. UI.Xaml; Windows. UI.Xaml.Controls; Windows. UI.Xaml.Controls.Primitives; Windows. UI.Xaml.Data; Windows. UI.Xaml.Input; Windows. UI.Xaml.Media; Windows. UI.Xaml.Navigation; namespace Hello { public sealed partial class MainPage : Page { public MainPage()... they needed to learn about the brave new environment of Windows, it was mostly the 2nd edition (published in 1990 and focusing on Windows 3) and the 3rd edition (1992, Windows 3.1) that helped out When the Windows API graduated from 16-bit to 32-bit, Programming Windows responded with the 4th edition (1996, Windows 95) and 5th edition (1998, Windows 98) Although the 5th edition is still in print, the... particularly compared with the setup I used to write the first edition of Programming Windows But that was 25 years ago The Programming Windows Heritage This is the 6th edition of Programming Windows, a book that was first conceived by Microsoft Press in the fall of 1986 The project came to involve me because I was writing articles about Windows programming for Microsoft Systems Journal at the time I still get... “The Microsoft Guide to Programming for the MS-DOS Presentation Manager: Windows 2.0 and Windows/ 386.” The reference to Presentation Manager reminds us of the days when Windows and the OS/2 Presentation Manager were supposed to peacefully coexist as similar environments for two different operating systems The first edition of Programming Windows went pretty much unnoticed by the programming community... grounds of efficiency, and Windows has even sparked some energetic controversy once again Windows 8 is easily the most revolutionary updating to Windows since its very first release in 1985, but many old-time Windows users are wondering about the wisdom of bringing a touch-based interface tailored for smartphones and tablets to the mainstream desktop I suppose that Programming Windows could only be persuaded... 5th, I used the C programming language Sometime between the 3rd and 4th editions, my good friend Jeff Prosise said that he wanted to write Programming Windows with MFC, and that was fine by me I didn’t much care for the Microsoft Foundation Classes, which seemed to me a fairly light wrapper on the Windows API, and I wasn’t that thrilled with C++ either As the years went by, Programming Windows acquired... new Windows 8 applications  Windows. * Windows Runtime (or WinRT) As suggested by the list of using directives, namespaces that begin with Windows. UI.Xaml play a major role in the Windows Runtime Following the using directives, this MainPage.xaml.cs file defines a namespace named Hello (the same as the project name) and a class named MainPage that derives from Page, a class that is part of the Windows. .. writing Windows 8 applications, each of which involves a programming language and a markup language:  C++ with XAML  C# or Visual Basic with XAML  JavaScript with HTML5 In each case, the Windows Runtime is supplemented by another programming interface appropriate for that language Although you can’t mix languages within a single application, you can create language-independent libraries (called Windows. .. using Windows 1 (introduced over a year earlier in November 1985), but beta versions of Windows 2 soon became available In those years, editing and compiling a Windows program occurred outside of Windows in MS-DOS For editing source code, I used WordStar 3.3, the same word processor I used for writing the chapters From the MS-DOS command line, you would run the Microsoft C compiler and then launch Windows. .. publication of Brian Kernighan and Dennis Ritchie's classic book The C Programming Language (Prentice Hall, 1978), it has been customary for programming tutorials to begin with a simple program that displays a short text string such as “hello, world.” Let’s create a few similar programs for the new world of Windows 8 I’ll assume you have the Windows 8 Release Preview installed with the development tools and . used to write the first edition of Programming Windows. But that was 25 years ago. The Programming Windows Heritage This is the 6 th edition of Programming Windows, a book that was first conceived. on Windows 3) and the 3 rd edition (1992, Windows 3.1) that helped out. When the Windows API graduated from 16-bit to 32-bit, Programming Windows responded with the 4 th edition (1996, Windows. System.Linq; using Windows. Foundation; using Windows. Foundation.Collections; using Windows. UI.Xaml; using Windows. UI.Xaml.Controls; using Windows. UI.Xaml.Controls.Primitives; using Windows. UI.Xaml.Data;

Ngày đăng: 28/06/2014, 14:20

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN