A gadget is a lightweight and task-specific application that appears in the Windows Sidebar.. A Windows Sidebar gadget can provide information and functionality at your fingertips in the
Trang 1Developing Gadgets for the Windows Sidebar
Introduction
One of the important new features in Windows Vista is the Windows Sidebar and the
gadgets that are hosted by the Sidebar This section introduces these features and
describes how to build these features in Windows Vista
Objectives
After completing this section, you will be able to:
• Describe the Windows Sidebar
• Describe gadgets
• Install and use gadgets
• Explain how gadgets work
• Develop a gadget
• Package a Sidebar gadget
Trang 2What Is the Windows Sidebar?
Windows Sidebar is a pane on the side of the Windows Vista desktop that organizes
gadgets and makes them easy to access Windows Sidebar is the perfect complement to
widescreen monitors and also works seamlessly on standard displays You can easily
customize Windows Sidebar to suit how you want to interact with it—whether you want
it always on top or resting below maximized windows
Why use the Windows Sidebar?
The Windows Sidebar is designed to:
• Enhance productivity by hosting mini-applications for the desktop and the Web that
are optimized for work and home situations
• Be non-intrusive Windows Sidebar development should follow the Less is more
model and provide native support for standard and widescreen displays
• Provide a personalized experience with which each user gets more choice and control
• Experience great developer support The Windows Sidebar is simple to deploy using
the tools provided by Microsoft, and it is secure by design
Trang 3What Are Gadgets?
Gadgets are mini applications that perform specific functions, such as displaying a clock
face, converting international currencies, displaying CPU performance, or games A
gadget is a lightweight and task-specific application that appears in the Windows Sidebar
By default the Sidebar displays the Slideshow, the Clock and the RSS Feed Watcher to
new users There are three types of gadgets
• Information gadgets
• Application gadgets
• Utility gadgets
Trang 4Why use gadgets?
Gadgets are designed to:
• Fill the need for lightweight applications Gadgets are designed to fit in the gap between complete applications and icons in the notification area A Windows Sidebar gadget can provide information and functionality at your fingertips in the form of a lightweight application hosted in the Sidebar The developer can build a Sidebar gadget that integrates with a full-blown application to expose some data from the application
• Alleviate information overload People are barraged with information, and launching full applications or a browser is often more than is required People want easy-to-view and relevant information at their fingertips
• Take advantage of the increase in screen sizes Many computers now use 16 x 9 displays and multi-monitor configurations Gadgets extend the Windows shell to take advantage of the new hardware configurations
Trang 5Installing and Using Gadgets
Supported platforms for gadgets
Gadgets can run in several different platforms:
• Gadgets for Windows Sidebar will run on your desktop or dock into Windows
Sidebar
• Gadgets for the Web (Live.com) provide a fast, customizable home page with a clean
user interface—putting the users in control of more of their online experience These
gadgets can easily support docking into the Windows Sidebar
• Gadgets for Windows SideShow allow users to view information on devices that are
attached to the computer Gadgets for Windows SideShow run on the PC and use
COM interfaces to send data to devices
Installing gadgets
All gadgets for Windows Sidebar reside on a user’s computer The gadgets may be
acquired when a user downloads them from a Web site, when someone e-mails one, or
when an application installs one When a user encounters a gadget file, that user can
double-click to install the gadget, starting a process that informs the user about any risks
associated with gadgets and extracts the files for use by the Sidebar The gadget file
remains available for the user to archive or delete
Trang 6Running multiple instances of gadgets
Each gadget can be started multiple times For example, users could use a gadget to have many different clocks for various time zones or slideshow viewers of different picture collections This is possible because the gadget platform provides methods for developers
to store settings and associates settings with the correct instance of each gadget
automatically The gadgets also run automatically and with the same settings when the users log out or restart their computer
User interaction with gadgets
Each gadget can respond to user interaction Users may click within the gadget buttons, images, or text or move the gadget around the screen Developers can respond to both of these events through script by changing the gadget’s appearance as necessary
Trang 7How Gadgets Work
Each gadget is developed using HTML and any Internet-capable scripting language such
as JavaScript or VBScript A gadget also has access to extra information about itself and
Windows when the HTML is run as a gadget This allows a gadget to interact with
Windows files and folders so that it can show images from the users’ Pictures folder or
display information about a wireless connection Gadgets can also display a settings
dialog box and store those settings by using script You can create very complex and rich
gadgets by using only script and without using other binary objects
To create a gadget, you need a minimum of two items: an HTML file and a manifest file,
which must be named gadget.xml The HTML file that makes up the gadget itself is
actually the same as any Web page that uses dynamic HTML The manifest file is an
XML-formatted file that contains the configuration information for a gadget
Trang 8The following table lists the tags that should be used in the gadget.xml file
<name> Name of the gadget as it appears in the Gadget picker dialog box
<author> Name of the person who wrote the gadget
<copyright> Copyright information, including name of the copyright holder and
copyright date
<description> Brief description of the gadget and what it does
<icon> Name of the icon file
<code> Name of the HTML file that is core part of the gadget
<website> Web site associated with the gadget
When you click a particular gadget, the author, copyright, description tags, and icon all appear
Trang 9Developing a Gadget
Process for creating a gadget
Creating a gadget is a process that should be familiar to any Web page author:
1 Create a directory to contain the gadget files
2 Create an HTML page that does something interesting
3 Create the XML file for the gadget manifest
4 Test the newly created gadget from the Sidebar
5 Close the gadget to make changes as necessary
6 Open the gadget again in the Sidebar to view changes
You can use DHTML and XML to develop gadgets written with Microsoft Visual
Web Developer™ Express 2005 Visual Web Developer Express 2005 can be
downloaded from the Microsoft MSDN download site
Trang 10Gadget Object Model
Windows Sidebar and gadgets use the following object model which is exposed to the scripting environment
• Exposed Sidebar events
• Dock and Undock events These events are triggered when the gadget is being docked or undocked The specified script code runs when the event occurs
• Settings events Show, Closed, and Closing events are triggered by the settings dialog event and specify the script code that should be executed
• Exposed system functionality A Sidebar gadget developer needs to use only
DHTML to access the public interfaces through available methods to provide control over the gadget The following table is just a sample of the exposed functionality
System.Debug Exposes a method that allows for debugging functionality of a
running Sidebar gadget by outputting strings containing debugging information to a physical or virtual debugging terminal
System.Diagnostics Exposes a method that allows for extra gadget execution
information by allowing entries to be written to an event log for the gadget session
System.Environment Used to derive environment information regarding the user’s
current session in which Sidebar is running
System.Gadget Defines methods, events, and properties that are used to
identify and specify gadget configuration options within the Sidebar environment
System.Gadget.Settings This object and its methods are used to see if there are stored
settings for the gadget, such as when settings are saved from
an earlier session of a particular gadget instance
For more information see the Windows Sidebar Reference page on the Microsoft MSDN Web site
Trang 11Demonstration 3: Developing a Gadget
In this demonstration, you will see how to create a simple gadget and modify its settings
Key Points
The key points of this demonstration are that:
• Gadgets are fairly easy to develop
• You can modify gadget settings to display custom properties
Trang 12Packaging a Sidebar Gadget
Gadget deployment package components
The deployment package for a Gadget contains the following:
• The Gadget Description File (also known as a Gadget Manifest)
• An XML file defining the gadget properties, including name, icon, and
description
• The UI presentation
• Defines the core code for the gadget
• Resources (PNG files, localized strings)
• Images, script, and style sheets (For use in the HTML)
• Controller code (JavaScript files)
• An image (icon) for the Gadget picker
Trang 13Gadget Deployment Package
You can deploy gadgets via two primary file formats:
• A Zip file In this package type, the gadget files are collected and compressed into a single file Many tools, including Windows itself, can create, extract, and edit Zip
files
• A cab file A cab file, or Windows Cabinet File, can contain the files described
above The cab file appears to the user as a single file The package can be
code-signed as an option to provide additional information to users
The cab and Zip files must both end with the extension of gadget so that the Sidebar is
associated with that file This allows the Sidebar to open the packages when the user
downloads or double-clicks the file icon
Trang 14Demonstration 4: Packaging a Gadget
In this demonstration, you will see how to package a gadget file for distribution
Key Points
The key point of this demonstration is that:
• You can package a gadget file by adding the required files to a Zip file and then
renaming the file extension to gadget
Trang 15Application Interoperability and Migration
Introduction
One of the issues that an organization may need to deal with as it prepares to deploy
Windows Vista is testing the existing applications to ensure that they will run correctly
on Windows Vista Microsoft provides several tools to ease this process
Objectives
After completing this section, you will be able to:
• Describe how to test applications for Vista compatibility
• Describe the different known application incompatibility issues
• Explain how the Microsoft Application Compatibility Toolkit works
• Test application compatibility with the Standard User Analyzer
Trang 16Testing Applications for Vista Compatibility
To test and determine if an application is compatible with Windows Vista, complete
these steps:
1 Install Windows Vista on a test machine If you are upgrading the operating system
from Windows XP, first verify all application functionality in Windows XP
2 Install the application on the test machine If a prompt is displayed requesting
permission to install the application, click Permit, and then continue
If the application installation fails, try:
• Running the installation as an administrator To do this, right-click the
installer exe file, and then click Run this program as administrator
• If you still receive errors, try running the installation in the Windows XP SP2
compatibility mode
3 After the application is installed, try launching the application If the application did
not launch properly or if errors are displayed, apply the Windows XP SP2
compatibility mode to the application exe file, and then try again
4 Test the application and verify the application’s functionality Run through the full
suite of tests that would typically be used to test the application on Windows XP
Trang 17If the application does not install or launch successfully, or if it crashes, encounters an
error, or fails major functionality tests, it may be one of the small set of applications that are impacted by Windows Vista changes
As a best practice, consider using virtual machines created in Microsoft
Virtual PC 2004 and Microsoft Virtual Server 2005 to test applications and host
legacy applications that do not work on Vista
Trang 18Known Application Incompatibility Issues
The following table provides an overview of the known application incompatibility issues
in Windows Vista and provides a brief description and some remedial techniques that can
The internal version number for Windows Vista is 6
Application installers may not be able to install the application, and applications may not be able
to start
For applications and installers that check for the OS version, a Compatibility mode is provided in Windows Vista
Generally, applications should not perform OS version checks or, at a minimum, always accept version 6 or later for the OS
User Account
Control
Standard user applications that require administrative privileges to perform their tasks may fail or not make this task available to standard users
Custom installers, uninstallers, and updaters may not be detected and elevated to run as administrator
A user can launch the installer or updater by right-clicking the icon and then clicking Run This Program As Administrator
Apply the Windows XP SP2 compatibility mode from the Compatibility tab
Trang 19Do not install or update system components on Windows Vista except when using Microsoft- provided redistributable packages designed for Windows Vista
For registry keys protected by WRP, applications should gracefully handle Access Denied messages
Internet Explorer
Protected Mode
Applications that use Internet Explorer 7 will not be able to write directly to disk while in the Internet
or 32-bit kernel drivers will either fail
to start or will function improperly on
a 64-bit edition of Windows Vista
All 16-bit components should be removed from applications and replaced with 32-bit or 64-bit equivalents
All 16-bit installers should be converted to 32-bit or 64-bit installers
All 32-bit kernel drivers should be converted to 64-bit drivers
For a more complete resource, refer to The Windows Vista Developer Story:
Application Compatibility Cookbook page located on the Microsoft MSDN Web site
Trang 20What Is the Microsoft Application Compatibility Toolkit?
The Microsoft Application Compatibility Toolkit is a life-cycle management tool that
assists in identifying and managing your overall application portfolio, reducing the cost
and time involved in resolving application compatibility issues and helping you to
quickly deploy Windows Vista and Windows Updates
What can the Microsoft Application Compatibility Toolkit do?
The Microsoft Application Compatibility Toolkit provides the following tools to help in
planning you application migration:
• Software inventory analyzer The software inventory analyzer takes inventory of all
the applications installed on users’ desktops across the enterprise, stores that data in a
central location, and performs compatibility analysis against a compatibility database
• Filtering analysis reports These reports provide information about application
compatibility issues and mitigation information The level of detail of this
information is improved with user input
• Compatibility mitigation This provides custom compatibility databases based on
analysis and the ability to test the fixes to make sure they will work