270 likes | 592 Views
WCL322: The Windows API Code Pack – Add Windows 7 Features to Your Application. Kate Gregory Gregory Consulting www.gregcons.com/kateblog, @gregcons . It’s Simple, Really. If you have a Windows application, it should be a Windows 7 application. Agenda. What is different about Windows 7?
E N D
WCL322: The Windows API Code Pack – Add Windows 7 Features to Your Application Kate Gregory Gregory Consulting www.gregcons.com/kateblog, @gregcons
It’s Simple, Really If you have a Windows application, it should be a Windows 7 application.
Agenda • What is different about Windows 7? • Visuals • Taskbar jumplists • Taskbar overlays – icons and progress bars • Thumbnail buttons and custom thumbnails • Fundamentals • Power awareness • Network awareness • Libraries • Restart and recovery
Accessibility from managed code Easy • Directly-callable using. NET interop mechanisms • Eg RSS, Office • C++/CLI or PInvoke signatures • EgApplication Recovery and Restart • Raw Win32 • EgPower Management, Windows Vista Wizards • COM • EgSearch and Organize APIs • Extra difficult to call from managed code • EgCommon File Dialogs, Network Awareness Hard
What is the Windows API Code Pack? • Managed class library to access to Windows 7 features • Windows Shell namespace • Windows Vista and Windows 7 Task Dialogs • Support for Shell property system • Taskbar Jump Lists, Icon Overlay and Progress bar • Common file dialogs • Direct3D 11.0 and DXGI 1.0/1.1 APIs • Sensor Platform APIs • Extended Linguistic Services APIs • http://code.msdn.microsoft.com/windowsapicodepack
Highlights from Windows API Code Pack • All demos are from the samples that ship with it • All demos are provided in both VB and C# • Samples are designed as a source of code for you • But you would hardcode so much more • Run the apps to experiment and see what you like
What You Will See • Taskbar Jumplists • Taskbar Overlays • Taskbar Thumbnail Buttons • Restart and Recovery • Power Management
Taskbar - Jumplists demo
Taskbar Jumplists - destinations • Private jumpList As JumpList • jumpList.AddToRecent(fileName) • jumpList.KnownCategoryToDisplay = • JumpListKnownCategoryType.Recent • category1 = new JumpListCustomCategory(“My Category 1") • jumpList.AddCustomCategories(category1) • category1.AddJumpListItems(New JumpListItem(path)) • jumpList.AddUserTasks(jll)
Taskbar Jumplists - tasks • Dim p As String = Path.Combine(systemFolder, "notepad.exe") • Dim ir As IconReference = New IconReference(p, 0) • Dim jll As JumpListLink = New JumpListLink(p, • "Open Notepad") • jll.IconReference = ir • jumpList.AddUserTasks(jll)
Taskbar - Overlays demo
Taskbar Overlays • TaskbarManagerwindowsTaskbar = TaskbarManager.Instance • windowsTaskbar.SetOverlayIcon(Me.Handle,My.Resources.Green, "Green") • windowsTaskbar.SetProgressState( • TaskbarProgressBarState.Error) • windowsTaskbar.SetProgressValue( • currentValue, maxValue)
Taskbar Thumbnails • buttonFirst = • New ThumbnailToolbarButton( • My.Resources.first, "First Image") • AddHandlerbuttonFirst.Click, AddressOfbuttonFirst_Click • TaskbarManager.Instance.TabbedThumbnail. • SetThumbnailClip(Me.Handle, • New Rectangle(pictureBox1.Location, pictureBox1.Size))
Restart and Recovery • Register for Recovery • Chance to save your information on another thread • OS calls your code for you • Register for Restart • OS will run your app again (with a hint) after it dies
Restart and Recovery demo
Restart and Recovery • ApplicationRestartRecoveryManager. • RegisterForApplicationRestart(new RestartSettings("/restart", • RestartRestrictions.None)); • RecoveryData data = new RecoveryData( • new RecoveryCallback(RecoveryProcedure), null); • RecoverySettings settings = new RecoverySettings(data, 0); • ApplicationRestartRecoveryManager. • RegisterForApplicationRecovery(settings);
Power Management • Is the machine running on battery? • What can your application do to extend battery life? • Autosaveless frequently • Autosave before critical battery reached • Scale back the user experience • Graphics richness • Reduce the frequency of data updates • Stop spinning the CD for sound effects access • Reduce CPU work loads • Number of threads, thread priorities • Use hardware (not software) rendering for graphics • Turn off or constrain background processing • Defer unnecessary tasks
Power Management demo
Power Management • PowerManager.PowerSourceChanged += • new EventHandler(PowerSourceChanged); • PowerManager.PowerPersonality • PowerManager.PowerSource • PowerManager.GetCurrentBatteryState().EstimatedTimeRemaining
Code Pack • Gets managed developers working on Windows 7 now • WPF or Windows Forms • C# or VB • Not the only way to get there • Some of this is in WPF (.NET 4) • You could do your own interop, but why? • Others have written other wrappers • Documentation and samples • Discussions on Code Gallery • If you need to change or redistribute, you can
What you’ve seen • Taskbar • Jumplists – nouns and verbs • Icon overlays • Progress bar overlays • Thumbnail buttons • Thumbnail clipping • Restart and Recovery • Power Awareness
Call to Action • Download Code Pack • http://code.msdn.microsoft.com/windowsapicodepack • Add functionality to your application so it lights up on Win 7 • Feels like a Windows 7 app (taskbar etc.) • Never lose unsaved data to a crash again • Power efficiency and thoughtfulness
Resources • http://code.msdn.microsoft.com/WindowsAPICodePack • http://windowsteamblog.com/windows/b/developers • http://www.developforwindows.com/
Session Evaluations Tell us what you think, and you could win! All evaluations submitted are automatically entered into a daily prize draw* Sign-in to the Schedule Builder at http://europe.msteched.com/topic/list/ * Details of prize draw rules can be obtained from the Information Desk.
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. 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 provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.