Академический Документы
Профессиональный Документы
Культура Документы
W indows A
Accessibility
ccessibility
ET
.N
Volume 5 / Issue 4
Features
6 A Letter from the Director of Accessibility 36 Making Custom Controls Accessible
at Microsoft While there are many ways to make custom controls accessi-
ble, choosing the right solution can be tricky. With Microsoft®
“Our vision is to create innovative technology that is accessi- technologies, you can implement UI Automation, create or
ble to everyone and that adapts to each person’s needs. Acces- override properties with Dynamic Annotation, or close the gap
sible technology eliminates barriers for people with disabilities between Microsoft Active Accessibility and UI Automation.
and it enables individuals to take full advantage of their LeAnne Fossmeyer, Michael Bernstein, David Tseng, Vidhya Sriram
capabilities.” —Bill Gates, Chairman, Microsoft Corporation
Rob Sinclair
42 Microsoft Accessibility Testing Tools
8 Open Accessibility The few informal tests described in this article can expose
a plethora of usability and accessibility shortcomings, over-
Open accessibility is a term that describes both the need for sights, and other issues in your application. But how do you
and the realization of interoperability in assistive technolo- test, assess, and rectify them?
gies. This article describes open accessibility and the ways Karl Bridge
Microsoft and other software development organizations,
like Novell and the AIA, are working together to help user
access technology across platforms. 48 Internet Explorer 8 New Accessibility
Norm Hodne Features
Windows® Internet Explorer® 8 has a lot of cool new
10 Accessibility 101 features that make Web page browsing more accessible,
What is accessibility? Learn about the fundamentals of including Caret Browsing, Zoom version 2, high DPI, and
accessibility, the people that accessible technologies help, support for ARIA and UI Automation.
and the things you can do to help them interact smoothly JP Gonzalez-Castellan
and successfully with each other.
Jennifer Linn, Annuska Perkins 56 A Pragmatic Approach to WPF Accessibility
A Microsoft MVP shares his experience addressing ac-
16 Windows Automation API 3.0 Overview cessibility with Windows® Presentation Foundation and
The ecosystem of Windows® automation technologies adaptive technology vendors.
includes Microsoft® Active Accessibility and Windows Alvin Bruney
implementations of the UI Automation specification, which
provides more flexible programmatic access to UI elements.
62 Writing a UI Automation Provider
Masahiko Kaneko
UI Automation providers retrieve data about UI elements
for assistive technologies and automation tools. This article
22 What's new in Windows 7 Automation API walks through code samples for a UI Automation provider
Windows® 7 offers end–to-end accessibility with better for a Win32-based custom control.
performance, seamless interoperability, and improved Brendan McKeon
framework design.
Nazia Zaman, Matthew Karr 70 Creating UI Automation Client Applications
UI Automation enables a client application to investigate and
28 Creating Accessibility-aware Silverlight 2 manipulate the UI of all running applications on the system.
Content This article walks through codes sample that demonstrate the
basic features of UI Automation for client applications.
This article provides you with guidelines for taking advan- Matthew Karr
tage of Silverlight(TM) 2 features and building an accessible
Silverlight application.
Mark Rideout
Departments
7 Code Compilers
59 Advertisers Index
US subscriptions are US $29.99 for one year. Subscriptions outside the US pay US $44.99. Payments should be made in US dollars drawn on a US
bank. American Express, MasterCard, Visa, and Discover credit cards are accepted. Bill me option is available only for US subscriptions. Back issues
are available. For subscription information, email subscriptions@code-magazine.com or contact customer service at 832-717-4445 ext 10.
Subscribe online at www.code-magazine.com
CoDe Component Developer Magazine (ISSN # 1547-5166) is published bimonthly by EPS Software Corporation, 6605 Cypresswood Drive., Suite
300, Spring, TX 77379. POSTMASTER: Send address changes to CoDe Component Developer Magazine, 6605 Cypresswood Drive., Suite 300,
Spring, TX 77379.
t Microsoft®, our commitment to creating cessible applications. Eleven years later, Micro-
Rob Sinclair
Director of Accessibility
Microsoft Corporation
Volume 5 Issue 4
Group Publisher
Markus Egger
Associate Publisher
Rick Strahl
Managing Editor
Ellen Whitney
Content Editors
Kevin Fansler
Writers In This Issue
Michael Bernstein Karl Bridge
Alvin Bruney LeAnne Fossmeyer
JP Gonzalez-Castellan Norm Hodne
Masahiko Kaneko Matthew Karr
Jennifer Linn Brendan McKeon
Annuska Perkins Mark Rideout
Rob Sinclair Vidhya Sriram
David Tseng Nazia Zaman
Technical Reviewers
Markus Egger
Art & Layout
King Laurin GmbH
info@raffeiner.bz.it
Production
Franz Wimmer
King Laurin GmbH
39057 St. Michael/ Eppan, Italy
Printing
Fry Communications, Inc.
800 West Church Rd.
Mechanicsburg, PA 17055
Advertising Sales
Lake Quincy Media LLC
330-677-2440
ssmith@lakequincy.com
msmith@lakequincy.com
Sales Managers
Erna Egger
+43 (664) 151 0861
erna@code-magazine.com
Tammy Ferguson
832-717-4445 ext 26
tammy@code-magazine.com
Circulation & Distribution
General Circulation: EPS Software Corp.
Newsstand: Ingram Periodicals, Inc.
Media Solutions
Worldwide Media
Subscriptions
Circulation Manager
Cleo Gaither
832-717-4445 ext 10
subscriptions@code-magazine.com
Subscribe online at
www.code-magazine.com
Open Accessibility
Creating a natural user interface requires designers, testers,
and developers working in concert to develop the right support
that makes multi-modal access to an operating system and
applications possible. To assist in this work through the Accessibility
Interoperability Alliance (AIA), Microsoft® released its UI Automation
Specifications with a Community Promise and released testing tools as
open source projects via CodePlex. Microsoft is committed to interoperable
accessibility.
Norm Hodne
normanho@microsoft.com,
+1 (425) 704-7324 Making Technology Accessible number of users access technology in their daily lives.
and Interoperable By making UI Automation freely available Microsoft
Norm Hodne is the Lead
hopes to increase the accessibility of many informa-
Program Manager in the
The purpose of the AIA, formed recently by a coali- tion and communication technologies and to drive
Windows Experience Group tion of the world’s leading information and assistive cross-platform interoperability.
responsible for the accessibility technology (AT) companies, is to foster industry-wide
APIs, accessibility applications, collaboration aimed at reducing many of the barri-
and the speech commanding ers that people with disabilities frequently encounter Microsoft UI Automation:
and dictation features shipped when they try to access information and communi-
in Windows. An Innovative Accessibility Model
cation technologies, including Web sites.
Norm also is a representative UI Automation, a next-genera-
to the INCITS V2 standards To create accessible technol- tion accessibility programming
ogy products today, developers Fast Facts model, simplifies development
organization where he works
on standards related to work across multiple platforms, Novell will implement and reduces costs for AT devel-
application models, and types of UI Automation for Moonlight opers as well as IT application
accessibility.
hardware. To address interoper- developers who want to make
that will provide accessibility
ability issues arising from this their software compatible with
current environment, the AIA is capabilities for Silverlight AT products, such as screen
using a two-part strategy: First, applications on Linux. readers for people who are
the group is working to harmo- blind. UI Automation, which
nize current technologies to in- is available for Windows® XP,
®
teroperate more easily, reducing costs for developers Windows Vista , Windows 7, and is built into the
and creating more usable products for customers. Windows Presentation Foundation (WPF), Silver-
Second, it is working to create a unified accessibility light™ 2 and in additional products, offers developers
model that will serve the entire industry. In order to a richer and more efficient way to convey user inter-
support backwards compatibility and bridging tech- face commands and behaviors to a person through
nology to a full UI Automation their AT product.
implementation, Microsoft re-
leased the UI Automation Speci- UI Automation represents what the interface can
UI Automation fication with the UI Automation, do rather than how it is presented visually, making
allows developers to Microsoft Active Accessibility, it easier for both the application developer and as-
and IAccessibleEx specifications. sistive technology developers to create rich experi-
create assistive technologies ences for their users, including people who are blind.
across all platforms and Microsoft also released the UI Au- AT products built using UI Automation will require
tomation Specification to the AIA, fewer updates and fewer customizations for specific
help a larger number of users an engineering working group applications, because they can intelligently interact
access technology dedicated to making it easier for with user interfaces and controls that have yet to be
in their daily lives. developers to create software, invented.
hardware, and Web-based prod-
ucts that are accessible to people
with disabilities. The UI Auto- Linux Implementation
mation specification describes the latest accessibility
framework technology developed by Microsoft, and Microsoft developed UI Automation from the start
will help developers include advanced accessibility to be compatible for implementation on platforms
functionality into implementations designed for use other than Windows. Starting in 2008, a Novell
on any operating system. team is implementing UI Automation for Linux and
will support SUSE, Ubuntu, and Red Hat and make
UI Automation allows developers to create assistive the code available to other Linux distributions. Their
technologies across all platforms and help a larger implementation work has several goals:
Accessibility 101
We know what you’re thinking: Why should I read an article
about the fundamentals of accessibility? Well, if you already know
the percentage of computer users who have disabilities, can name at least
ten different categories of assistive technologies, and can describe the key
concepts involved in designing an accessible application, then you can
probably skip to the next article. However, if you’re unsure what accessible
technology is, then take a few minutes and keep reading. You’ll learn about
the main concepts around accessible technology, the people they help,
Jennifer Linn and things you can do to help them interact smoothly and successfully
jenlin@microsoft.com
with each other.
Jenny is a writer in the
Windows Experience group
and has been working with What We Mean When We Talk of solutions that makes computer use more comfort-
Accessibility for 8 years. able for some people and possible for others.
Currently her main focus is about Accessibility
on the MSDN Accessibility Accessible technology is a piece of software or hard- As a developer, one of your main concerns is to en-
Developers Center ware that makes it easier for someone to see, hear, sure that you provide programmatic access to your
(http://msdn.microsoft.com/en- and use a technology product, such as a computer application’s user interface elements. This enables the
us/accessibility/default.aspx) or a mobile device. It can be an assistive technology assistive technologies to get information about the UI
and internal accessibility (AT) product, a specially designed piece of software elements and expose that information to the assistive
guidelines for product groups. or hardware that accommodates technologies, which in turn relays
In her spare time, she enjoys someone’s disability (or multiple Fast Facts the information to the user. For
walking homeless dogs at the disabilities) and enables them to example, important information
Seattle Humane Society interact with a computer. These 57% of computer users that an AT needs includes type,
(http://www.seattlehumane.org) products are developed to work are likely or very likely to name, location, and current state
and reading about history. with a computer's operating sys- benefit from the use of of a UI element. They also need
tem and software. For example, a accessible technology. to know when changes in the
blind computer user may use as- UI occur. For information about
44% of computer users
sistive technology called a screen how to provide programmatic
reader to navigate an applica-
use some form of access using Microsoft’s acces-
tion’s interface and a computer accessible technology. sibility frameworks, Microsoft
user with ALS may use a word Users seek solutions UI Automation and Microsoft
prediction program to help fa- to make their computers Active Accessibility, see the Ac-
cilitate communicating thoughts easier to use, not for cessibility Developer Center on
and ideas. solutions based on their MSDN (http://msdn.microsoft.
health or disability. com/en-us/accessibility/default.
Many companies offer hardware aspx).
devices, accessories, aids, and Making accessibility options
software applications that fall easier to discover and Programmatic access is just one
under the umbrella of assistive use will result in computers of the key concepts of creating
technology. For an overview of that are easier to use, accessible applications. The
assistive technology categories, more convenient, following section presents ad-
see Descriptions of Assistive and more comfortable for ditional concepts about acces-
Technology Products at the end computer users. sible design.
of this article.
Accessible technology can also be a feature built into Who Benefits from
a product that allows someone to adjust the settings Accessible Technology?
to meet their needs. Examples of accessibility fea-
tures include those that allow a user to increase font Although most accessible technology was originally
size, change font settings, or choose different colors intended and designed for individuals with severe
for their computer screen display. Other examples disabilities, accessible technology is widely used by
are the option for users to receive announcements computer users of all abilities today. Among adult
from their computer through sound notifications (a computer users in the United States:
"ding" when new e-mail messages arrive), or visual
notifications (a modal dialog flashes and beeps when • 1 in 4 has a visual disability.
the user tries to click away from it). So overall it is • 1 in 4 has a dexterity disability.
helpful to think of accessible technology as a range • 1 in 5 has a hearing disability.
Windows Automation
API 3.0 Overview
While general accessibility requirements (such as font colors
in UI rendering) are important, programmatic access to the
graphical user interface (GUI) is a crucial element to improving
accessibility. On the Windows® operating system, Microsoft® Active
Accessibility® and User Interface (UI) Automation support this programmatic
Masahiko Kaneko access. This article provides a quick overview of Windows Automation API
mkaneko@microsoft.com 3.0 featured in Windows 7.
Masahiko Kaneko is a Senior
Program Manager on the
User Interface Platform Team
in the Windows Experience Windows Automation API 3.0: cessibility refers to the application or control offering
Division. A program manager the UI for accessibility as the server, while UI Auto-
in accessibility at Microsoft a Bit of History
mation refers to this as the provider.
for more than 10 years, he Today, the Windows operating system offers two
has been involved with several application programming interfaces (API) specifi- Microsoft Active Accessibility offers a single COM
releases of the Windows cations for user interface accessibility and software interface with a fixed, small set of properties. UI Au-
Operating System as well as test automation. The legacy API, Microsoft Active tomation offers a richer set of properties, as well as a
many other Microsoft products. Accessibility, was introduced to set of extended interfaces called
Masahiko enjoys road biking, Windows 95 as a platform add- Fast Facts control patterns to manipulate
on in 1996. The new API is a automation elements in ways
XC skiing, music, and movies
Windows implementation of UI Automation is designed Microsoft Active Accessibility
in his free time but most of it is
the User Interface Automation for a modern and evolving cannot.
now dedicated to his first son
who is turning 18 months in
specification called UI Automa- user experience. The latest
tion. UI Automation was intro- Windows 7 implementation While UI Automation previ-
September.
duced in Windows Vista® and ously had both managed and
helps applications be
.NET Framework 3.0. unmanaged API for providers,
compatible with existing the original release had no un-
Although the two technologies accessibility applications managed interfaces for clients.
are different, the basic design while fully supporting new With Windows Automation API
principles are similar. Both ex- user interface paradigms. 3.0, you can finally write UI Au-
pose the UI object model as UI Automation is actually tomation clients entirely in un-
a tree hierarchy rooted at the faster and more reliable managed code.
desktop. Microsoft Active Ac-
than its predecessor,
cessibility represents individual The new API also provides sup-
UI elements as accessible ob-
Microsoft Active Accessibility. port for transitioning from Mi-
jects, and UI Automation rep- crosoft Active Accessibility serv-
resents them as automation elements. Both refer to ers to UI Automation providers. The IAccessibleEx
the accessibility tool or software automation pro- interface enables legacy Microsoft Active Accessibil-
gram as the client. However, Microsoft Active Ac- ity servers to add support for specific UI Automation
patterns and properties without rewriting their whole
implementation. The specification also allows in-pro-
cess Microsoft Active Accessibility clients to access UI
Automation provider interfaces directly, rather than
through UI Automation client interface.
Interoperability between
Microsoft Active Accessibility-based and
UI Automation-based Applications
The UIA-to-MSAA Bridge enables Microsoft Active
Accessibility clients to access UI Automation provid-
ers by converting the UI Automation object model to
a Microsoft Active Accessibility object model (Fig- Figure 4: The MSAA-to-UIA Proxy enables UI Automation clients to access Microsoft Active
ure 3). Similarly, the MSAA-to-UIA Proxy (Figure 4) Accessibility servers.
translates Microsoft Active Accessibility-based server
object models for UI Automation clients.
Limitations of
Now with IAccessibleEx, you can also improve ex- Microsoft Active Accessibility
isting Microsoft Active Accessibility server imple-
mentations by adding only required UI Automation Microsoft designed the Microsoft Active Acces-
object model information. The MSAA-to-UIA Proxy sibility object model about the same time as Win-
takes care of incorporating the added UI Automa- dows 95 released. The model is based on “roles”
tion object model. defined a decade ago, and you cannot support new
Figure 5: This UI Automation tree represents all elements on the Run dialog.
Property Description
AutomationId A string containing the UI Automation identifier (ID) for the automation
element. The AutomationId property of an element is expected to be the
same in any instance of the application, regardless of the local language.
BoundingRectangle The coordinates of the rectangle that completely encloses the element. The
returned rectangle is expressed in physical screen coordinates.
Name A string for the text representation of the element. This string should always
be consistent with the label text on screen. For example, the Name property
must be “Browse…” for the button labeled “Browse…”.
ControlType A ControlType of the automation element, which defines characteristics of
the UI element by well known UI control primitives such as button or check
box.
FrameworkId A string for the name of the underlying UI framework. FrameworkId enables
client applications to apply special cases to a particular UI framework.
Examples of property values are "Win32", "WinForm", and "DirectUI".
Table 2: Examples of UI Automation Element properties.
W3C ARIA Role MSAA Role UIA Control Type UIA AriaRole Property
button ROLE_SYSTEM_PUSHBUTTON button button
checkbox ROLE_SYSTEM_CHECKBUTTON Checkbox checkbox
combobox ROLE_SYSTEM_COMBOBOX Combobox combobox
grid ROLE_SYSTEM_TABLE DataGrid grid
gridcell ROLE_SYSTEM_CELL DataItem gridcell
group ROLE_SYSTEM_GROUPING Grouping group
img ROLE_SYSTEM_GRAPHIC Image img
link ROLE_SYSTEM_LINK HyperLink link
list ROLE_SYSTEM_LIST List list
menu ROLE_SYSTEM_MENUPOPUP Menu menu
presentation ROLE_SYSTEM_PANE Pane presentation
progressbar ROLE_SYSTEM_PROGRESSBAR ProgressBar progressbar
radio ROLE_SYSTEM_RADIOBUTTON RadioButton radio
slider ROLE_SYSTEM_SLIDER Slider slider
tooltip ROLE_SYSTEM_TOOLTIP Tooltip tooltip
tree ROLE_SYSTEM_OUTLINE Tree tree
treegrid ROLE_SYSTEM_TABLE DataGrid treegrid
Table 1: W3C ARIA Roles can be mapped to Microsoft Active Accessibility roles and UI Automation control types and AriaRole properties.
To support the ARIA specification, the UI Automa- to various properties and functions of Microsoft
tion specification enables developers to associate Active Accessibility and UI Automation.
UI Automation AriaRole and AriaProperties at-
tributes with W3C ARIA Roles, States, or Proper- UI Automation also offers a simple text object
ties. This helps user applications such as Internet model with the TextPattern pattern, which supports
Explorer support the ARIA object model in the embedding objects in a document object. This en-
context of UI Automation while keeping a baseline ables user agents and client applications to treat
accessibility object model. Web content either as an HTML document or as a
traditional desktop UI depending on the end-user
Some parts of the ARIA specification can be scenarios.
mapped to the desktop-oriented Microsoft Active
Accessibility object model; however, much of the With these features, UI Automation enables both
specification can only be applied to rich Internet the support of and extension of the W3C ARIA
applications. Table 1 lists some examples of map- specification without a dependency on a specific
pings from W3C ARIA Roles to Microsoft Active application or browser.
Accessibility Roles and UI Automation Control
Types.
Conclusion
For example, the ARIA Role checkbox is sup-
ported in Microsoft Active Accessibility by the With application user interfaces growing more and
role ROLE_SYSTEM_CHECKBUTTON and more complex, getting accessibility right is a challenge
in UI Automation by the combination of con- for developers. Programmatic access to the UI is criti-
trol type Checkbox and AriaRole checkbox. The cal in the development of assistive technologies like
ARIA state checked is supported in Microsoft Ac- screen readers and magnifiers. To address this, the
tive Accessibility by the state STATE_SYSTEM_ Windows 7 Automation API aims to provide a com-
CHECKED and in UI Automation by the control plete end-to-end, flexible, extensible, and consistent
pattern Toggle Pattern and the AriaProperties framework with improved design and performance.
property checked.
For further details, please refer to the Windows 7
ARIA States and Properties are supported by the SDK or the MSDN Accessibility Developer Center
UI Automation AriaProperties property with the (http://msdn.microsoft.com/accessibility/).
following exceptions: ARIA properties that take
object references (like the describedby property),
and ARIA properties already supported by the ac- Nazia Zaman
cessibility object model. Table 2 lists examples of Matthew Karr
mappings from W3C ARIA States and Properties
Creating Accessibility-aware
Silverlight 2 Content
If you haven't heard, accessibility is one of the most important
aspects of a Web site experience. By using the accessibility features in
Silverlight™ 2, you can provide the best experience for all users. Building a
rich Internet experience can be a daunting task when you have to balance a
cool visual design with usability.
Mark Rideout
markri@microsoft.com
(425)-703-1688 sability goes beyond the initial determination elements into two types: simple visuals that usually
Mark Rideout is a Program
Manager on the Silverlight
Team at Microsoft. Mark is
U that a user interface (UI) "makes sense" as the
UI has to be accessible to everyone. Silverlight
2 enables building a cool and accessible experience,
derive directly from the FrameworkElement class,
or functional controls that derive from the Control
class. A TextBlock, Image, or MediaElement are ex-
whether you are building an entire Silverlight appli- amples of simple visuals while a Button, TextBox, or
responsible for features around cation or just a few Silverlight controls. This article ListBox are examples of functional controls.
text and text input in addition to provides you with guidelines for taking advantage
input and accessibility features. of these features and building an accessible Silver- Along with the visual tree of elements, your Silver-
Mark has worked on multiple light application. light 2 application has a corresponding accessibil-
Microsoft UI frameworks ity tree. UI Automation presents three accessibility
such as Windows Forms and If you attempted to add accessibility to your Sil- views of the visual tree: a control view, a content
has been working with the verlight 1 content, you probably found that there view, and a raw view. Generally, all elements that
.NET Framework since 1.0. wasn't much support except for derive from Control show up
Mark started at Microsoft in something analogous to "alt" in the control view while ele-
1997, and prior to that, Mark text for screen readers. Silver- Fast Facts ments that derive directly from
worked as a consultant where light 2 on the other hand pro- FrameworkElement show up
Accessibility is an
he designed and developed vides necessary features that in the content view. TextBlock
business applications. you can build on. ever-increasing requirement can appear in either the con-
as you develop applications. tent view when used inside a
Mark enjoys everything Lego, Silverlight 2 provides
In general, when you build your control or data template or the
pinball, and Disneyland. He
Web application with accessibil- the tools you need to make control otherwise. If you cre-
enjoys teaching his 2-year-old
daughter about everything he
ity in mind, there are a general your application accessible ate custom Silverlight controls,
set of areas to think about: but you need to understand you can identify whether it’s a
likes. control, content, or both (or
how best to do it.
• Screen reader support. none).
• Keyboard navigation.
• High contrast presentation. There are different ways to think of elements be-
ing visible or invisible. Silverlight 2 reports elements
whose Visibility property is equal to Visibility.Col-
Ensuring Your Silverlight 2 Content lapsed as hidden, but reports elements that are in
Supports Screen Readers the tree and "hidden" from view as being visible el-
ements. This distinction is important because you
Silverlight 2 provides information to screen readers might style your app to have different UI "modes"
about your application via the new UI Automation by just z- ordering the elements. If you have rea-
framework. At the application level, you work with sons for not setting the Visibility property, then you
UI Automation using the AutomationProperties should at least disable controls that are "hidden"
class and its corresponding properties. When creat- from view to ensure that screen readers don't at-
ing custom controls or extending controls, you work tempt to interact with them.
with AutomationPeer and the UI Automation pro-
vider interfaces. This article looks at some impor-
tant UI Automation concepts you should be aware XAML Tag Your Elements
of as you build your Silverlight 2 application.
As you develop your Silverlight application, you
sometimes need to provide additional accessibility
Silverlight Accessibility Tree information to ensure your content is readable. For
example, screen readers won't know anything about
Your Silverlight 2 application is comprised of many your Image element except that it is an image. As
visual elements from Borders to Control-based ele- with HTML, you need to provide "alternative" text-
ments. For the most part, you can split the visual based information. With Silverlight, you provide al-
If you create your own control with its own Auto- Lastly, instead of putting the onus on the applica-
mationPeer functionality, then you are responsible tion developers using your custom control, you
should add the logic necessary to customize the erating system does not support UI Automation,
controls visual style based upon the high contrast and the Mozilla plug-in technology does not sup-
option mentioned earlier in this article. port interaction with the OS X accessibility frame-
work.
OS Limitations
Conclusion:
For Silverlight 2, the operating system and, to some Silverlight’s Accessible Future
extent, the browser dictate the level of accessibility
that Silverlight can provide. With Silverlight 2, you can control high contrast
styles, keyboard navigation, and screen reader sup-
Silverlight is a Web browser plug-in based upon ei- port. You can even take advantage of UI Automa-
ther Mozilla plug-in or Microsoft ActiveX technol- tion wherever it’s implemented. Silverlight’s new
ogy, depending upon the browser. The Web browser features can help you build Web applications and
is responsible for providing operating system inter- controls that support accessibility, so all users can
action and notifications with the plug-ins contained gain enjoyment and value from your work. And re-
on a Web page. In some cases, a plug-in can work member, when you design, do it with accessibility
directly with the operating system and bypass the in mind.
browser.
STDMETHODIMP get_ProviderOptions(
Part I: Implementing UI Automation ProviderOptions* pRetVal);
Here, you get the pattern provider for the toggle Dynamic Annotation provides three different mech-
pattern: anisms for handling annotations: Direct Annota-
tion, Value Map Annotation, and Server Annota-
HRESULT CCheckbox3UIAProxy::GetPatternProvider( tion. In this article I discuss only Direct Annotation
PATTERNID patternId, and Server Annotation.
Listing 1: The Toggle Pattern supports the binary status of a check box control.
// IToggleProvider to support the Toggle control pattern. *pRetVal = ToggleState_On;
HRESULT CCheckbox3UIAProxy::Toggle() }
{ break;
HRESULT hr = CheckAlive();
if (SUCCEEDED(hr)) case MIXED:
{ {
_pControl->MoveToNextState(); *pRetVal = ToggleState_Indeterminate;
} }
return hr; break;
}
case UNCHEcKED:
HRESULT CCheckbox3UIAProxy::get_ToggleState(ToggleState* pRetVal) {
{ *pRetVal = ToggleState_Off;
HRESULT hr = CheckAlive(); }
if (SUCCEEDED(hr)) break;
{ }
switch(_pControl->CheckboxCheckedState()) }
{ return hr;
case CHECKED: }
{
Designing a UI Automation
LeAnne Fossmeyer
object model for a new user Michael Bernstein
interface is straightforward if you David Tseng
Vidhya Sriram
follow a few basic principles.
Microsoft Accessibility
Testing Tools vs. the Ten-ton
Gorilla of Accessibility
Guidelines Compliance
Karl Bridge Close your eyes, ignore your mouse, navigate with your keyboard,
Karl Bridge is a Programming and rely on your ears alone. Now try to use an application you’ve
Writer, specializing in developer built or tested. Can you? The few informal tests described in this
content, for the Windows
Experience (WEX) organization
article can expose a plethora of usability and accessibility shortcomings,
at Microsoft. oversights, and other issues in your application. But how do you test, assess,
As the name implies, WEX is and rectify them?
focused on the Windows user
experience for consumers,
o ensure the most consistent user experience by exposing control properties, methods, and
IT professionals, and
developers. Karl has written
extensively for MSDN and the
Windows SDK with a focus on
T across the Microsoft® Windows® product line,
Microsoft has developed a number of tools to
assist developers and testers to verify the accessi-
events such that you can use a tool to manipulate
and interact with the UI manually or through au-
tomation.
bility implementations in their
making the Windows developer
applications. By incorporating the relevant
community a happy and Fast Facts components of the Windows
integral part of the Windows
In this article, I describe each According to a study that Automation API and follow-
experience. Prior contributions
of these tools and explain what ing common accessible de-
include the developer Microsoft commissioned
they are designed to test and sign practices, developers and
documentation for managed UI
the scenarios in which each
and Forrester Research testers can make applications
Automation and the Windows tool, alone or in combination, conducted: running on Windows signifi-
Vista Sidebar platform. may be useful. I also describe cantly more useful for people
• 40% (51.6 million) of
Causing confusion, how you can use these tools with vision, hearing, or motion
computer users with mild
consternation, and occasional throughout the development disabilities.
cycle and how to incorporate difficulties or impairments
despair amongst Karl's family,
them into automated and non- are likely to benefit from In the following sections I
friends, and co-workers are
his mid-Atlantic sensibilities— automated test frameworks. the use of accessible briefly describe the frameworks
a confluence of English technology. that constitute the Windows
eccentricity tempered with • 17% (22.6 million) of Automation API.
Canadian reserve and further An Overview of the computer users with
jumbled by numerous strolls Windows Automation severe difficulties or
through Europe, the Middle
Microsoft Active
Frameworks impairments are likely to
East, North Africa, and Asia. Accessibility
benefit from the use of
Fortunately, Karl has a spell-
The tools I discuss in this ar- accessible technology. Microsoft Active Accessibility
checker and an editor to buffer
ticle are designed to test and is a set of COM interfaces and
readers from the inevitable
report on a set of standardized APIs that provide the means to
mélange of mid-Atlantic accessibility issues typical of an application user expose and collect information about UI elements
spelling and grammar. interface (UI). The tests rely on programmatic ac- and controls. This allows assistive technologies,
cess of the UI implementing the relevant API com- test tools, and automation frameworks program-
ponents defined in the framework known as the matic access to and manipulation of the UI.
Windows Automation API.
42 Microsoft Accessibility Testing Tools vs. the Ten-ton Gorilla of Accessibility Guidelines Compliance www.code-magazine.com
is a newer technology that provides a much richer execution based on a set of predefined test cases.
object model than Microsoft Active Accessibility, Depending on the sophistication of the tool, I will
and it is compatible with both Win32® and .NET. supply generic recommendations for specific issues
uncovered during testing.
Note: UI Automation exposes each object in the UI
as an AutomationElement object to client applica- In addition to compiling reports for basic unit
tions. An AutomationElement object exposes com- tests, some of the tools discussed also offer support
mon properties of the UI element it represents, such for regression and integration testing. This abil-
as the control type and relevant control patterns that ity to find and track an accessibility bug through
provide properties specific to the control type. to resolution in a process you can automate makes
these tools indispensible additions to a tester’s
toolkit.
The IAccessibleEX Interface
Where to Get
The IAccessibleEX interface is a new interface the Tools
that provides the ability for developers to add par- Despite the name, The tools discussed in this
tial support for UI Automation to controls with
existing IAccessible COM interface implementa- the Windows Automation API article are available from
tions. This is transparent to testers and the tools encompasses both accessibility various locations,
discussed in this article. which I’ve listed below.
and automation frameworks.
UI Automation Verify
Evaluating the Accessibility Available from CodePlex,
of Your Application the Microsoft open-source
And in this Corner, We Have… The Tools project-hosting Web site:
There are two primary approaches to evaluating http://www.codeplex.com/
the accessibility of an application: a manual audit The following Microsoft tools enable developers to UIAutomationVerify
based on a set of commonly accepted heuristics for test accessibility implementations and functionality
an accessible UI (also known as static testing) and in applications using Microsoft Active Accessibility UI Spy
a partial audit to a fully automated test platform or UI Automation. UI Spy typically ships with the
that evaluates the implementation of an accessibil- Windows SDK. However, since
ity framework within your application’s code (dy- it did not ship in the Windows
namic testing). Both methods can provide results UI Automation Verify SDK for Windows Server 2008
based only on a set of guidelines, either from the and .NET Framework 3.5,
heuristics of the audit or those built into the design UI Automation Verify (UIA Verify) is a test auto- released in February of 2008,
of the accessibility framework. mation framework that facilitates automated testing you can find it in the earlier
for specific Microsoft UI Automation implementa- Windows SDK for Vista Update:
tions. This framework provides the basis for the UI
http://www.microsoft.
Accessibility Auditing Automation Test Library command-line tool and
com/downloads/details.
Visual UI Automation Verify (Visual UIA Verify), a
aspx?familyid=4377F86D-
Typically, auditing your application for accessi- Windows-based graphical user interface (GUI) for
C913-4B5C-B87E-EF72E-
bility issues is a manual process that involves at- the test framework. Most of the UIA Verify frame-
5B4E065&
tempting to access and use the full functionality work functionality is provided through a DLL (UI-
displaylang=en
of the application exclusively through keyboard ATestLibrary.dll) that enables the testing of specific
input and other assistive technologies (such as UI Automation functionality and that logs the test
screen readers). As an auditor, you assess each is- results.
sue discovered during the audit and log a bug
for each issue as necessary. You then assign a Note: The Visual UIA Verify GUI does not sup-
priority and severity to each bug and, where port event monitoring or testing and validating
possible and appropriate, provide recommenda- text-based content using the UI Automation Text-
tions for fixing or working around the issues that Pattern and TextPatternRange control pattern in-
the audit uncovers. These recommendations are terfaces. The UI Automation Test Library does not
based on a combination of experience and acces- share these limitations.
sibility guidelines from industry or advisory groups.
To use the UI Automation Test Library, a driver (or
Since there is an inherent risk of testing the func- client) application obtains an AutomationElement
tionality of the tool rather than the application, object from a control that requires verification. The
auditing should be conducted by seasoned testers driver, in turn, supplies the AutomationElement
familiar with accessibility requirements and the object to the UI Automation Test Library, which ex-
broad range of assistive technologies. ecutes the tests required to validate the UI Automa-
tion implementation. Figure 1 illustrates the typi-
cal workflow when using the UI Automation Verify
Accessibility Testing framework to test an application.
For the purposes of this article, accessibility test- The Visual UIA Verify framework is a Windows
ing is associated with automated, repeatable code driver for the UI Automation Test Library. This tool
www.code-magazine.com Microsoft Accessibility Testing Tools vs. the Ten-ton Gorilla of Accessibility Guidelines Compliance 43
is designed for manual testing. It provides an inter-
face to UI Automation Test Library functionality
and eliminates the code overhead of a command-
line tool. Figure 2 illustrates the five functional ar-
eas of the Visual UIA Verify framework.
UI Spy
Figure 2: The five functional areas of the Visual UI Automation Verify framework.
44 Microsoft Accessibility Testing Tools vs. the Ten-ton Gorilla of Accessibility Guidelines Compliance www.code-magazine.com
If you don't need the entire
SDK, you can get the .NET
Framework Tools with UI Spy
by downloading the Windows
SDK for Vista Update. This will
install side by side with the new
Windows SDK for Windows
Server 2008. For example: C:\
Program Files\Microsoft SDKs\
Windows\v6.0\Bin (with UISpy)
or C:\Program Files\Microsoft
SDKs\Windows\v6.1\Bin
UI Accessibility Checker
AccChecker is available from
CodePlex, the Microsoft open-
source project hosting Web
site: UI Accessibility Checker:
http://www.codeplex.com/
AccCheck
Inspect Objects, Accessible
Explorer, and Accessible Event
Watcher
These tools are available as
individual downloads from the
Microsoft Active Accessibility
2.0 Software Development
Kit (SDK) Tools Web site:
http://www.microsoft.
com/downloads/details.
aspx?familyid=3755582A-
A707-460A-BF21-
1373316E13F0&
displaylang=en#filelist
Figure 3: The control view of UI Spy querying displays the UI Automation properties of an element,
running with limited user access.
means for developers and testers to verify that an content using the TextPattern and TextPattern-
application UI is programmatically accessible to as- Range control pattern interfaces of UI Automation.
sistive technology devices. Figure 3 shows UI Spy
querying and displaying the UI Automation proper-
ties of an element. UI Accessibility Checker
UI Spy is similar to Visual UIA Verify in that it does UI Accessibility Checker (AccChecker) verifies the
not support the testing and validation of text-based design and implementation of Microsoft Active
www.code-magazine.com Microsoft Accessibility Testing Tools vs. the Ten-ton Gorilla of Accessibility Guidelines Compliance 45
This ability to find and
track an accessibility bug
through to resolution in a process
you can automate makes these
tools indispensible additions to a
tester’s toolkit.
Inspect Objects
Accessible Explorer
46 Microsoft Accessibility Testing Tools vs. the Ten-ton Gorilla of Accessibility Guidelines Compliance www.code-magazine.com
tionality that is very similar to the Inspect tool.
However, it differs in two important features:
Figure 7 illustrates how the AccEvent tool catches Figure 6: The AccExplorer tool can test specific Microsoft Active Accessibility properties in the
the toolbar clock events. Notepad content pane.
Conclusion
No tool alone can definitively test and guaran-
tee compliance with all accessibility guidelines.
However, the tools described in this article make
achieving that goal significantly easier through
their comprehensive coverage of the many accessi-
bility compliance issues that software vendors face
today.
Karl Bridge
www.code-magazine.com Microsoft Accessibility Testing Tools vs. the Ten-ton Gorilla of Accessibility Guidelines Compliance 47
ONLINE QUICK ID 0811092
Figure 2: Pressing the context menu key brings up the context menu; so you can access Web Accelerators using only the
keyboard.
Screen Resolution: Changing from a 1200 × as big on the 800 × 600-pixel screen as it was on the
1600-pixel screen resolution to an 800 × 600-pixel 1200 × 1600-pixel screen.
resolution means changing the spacing between
pixels. In other words, pixels are effectively bigger. System DPI: Changing from 96 DPI to 192 DPI,
A screen element of 100 × 100 pixels is now twice but keeping all other factors the same, implies more
HTML Layout Measurements: This value is al- You can see the importance
ways 96 DPI, as explained in the CSS 2.1 speci- of carefully selecting
fication (http://www.w3.org/TR/CSS21/syndata.
the anchor for positioned elements
and using relative dimensions
instead of absolute or
device-dependent dimensions
(such as pixels).
Listing 1: Sample Web page to understand better the new Zoom. The boxes in Figure 4 are absolutely positioned,
and they are anchored to the corners of the view-
<html> port. Each is sized using relative dimensions (%).
<head> The box in the middle is anchored to the center
<title> Zoom 2 Sample </title> of the body. In Figure 5, you can see how Inter-
net Explorer 7 displays a 175% zoom while Figure
</head> 6 shows how Internet Explorer 8 handles a 175%
zoom.
<style>
You can see the importance of carefully selecting
div { the anchor for positioned screen elements and
width: 50%; height: 50%; position: absolute; using relative dimensions instead of absolute or
} device-dependent dimensions (such as pixels). If
you had positioned the center DIV using pixels,
#center { the DIV would have moved from the center when
width: 20%; height: 20%; left: 40%; zoomed.
top: 40%; border: 5px black solid;
}
High DPI
</style>
You can use the Windows DPI Scaling (https://window-
<body style="border:0; padding:0;"> shelp.microsoft.com/Windows/en-US/help/454f5078-2b51-
4cda-b4c0-6391e870c41d1033.mspx) feature to scale
<div id="red" style="left:0; top:0; width:50%; up Windows fonts and user interface (UI) elements
height:50%; background-color:red;"> Red </div> (such as buttons, icons, input fields, and so on) by
a given percentage. This is different from the scaling
that occurs when you lower the display resolution be-
<div id="blue" style="left:50%; top:0; width:50%;
cause in the DPI Scaling case, Windows is providing
height:50%; background-color:blue;"> Blue </div>
fonts and UI elements that are drawn with more pix-
els, resulting in a larger, higher fidelity, and sharper
<div id="yellow" style="left:0; top:50%; width:50%;
Windows experience.
height:50%; background-color:yellow;"> Yellow </div>
Like Windows Vista, the Internet Explorer 8 user
<div id="green" style="left:50%; top:50%; width:50%;
interface is entirely DPI Scaling-aware, and you
height:50%; background-color:green;"> Green </div>
will notice that all UI elements and fonts are scaled
accordingly. Additionally, larger and higher fidelity
</body> icons are used. Notice the difference in the Internet
Explorer chrome when Windows DPI Scaling is set
</html> to 96 DPI (Figure 7) and 120 DPI (Figure 8).
ARIA syntax is
a great mechanism to
unlock your dynamic,
rich Web applications
for everyone.
Application
Development
• .NET 3.0 (WPF, WCF)
• Windows & Smart Client
• ASP.NET & AJAX Web
• Tablet PC & Mobile PC
• Windows Mobile
Prototyping Services
Situation Assessment
Project Management
Mentoring
Training
Contact us at:
info@eps-software.com
866-529-3682
www.eps-software.com
ONLINE QUICK ID 0811102
A Pragmatic Approach to
WPF Accessibility
As is often the case, applications are not typically designed
with accessibility in mind. Usually, applications are designed to satisfy
business requirements. If those business requirements do not include
accessibility, more likely than not, the application as a whole will be
inaccessible to important segments of users. There are, however, steps you
Alvin Bruney can take to mitigate this common lack of foresight in requirements analysis.
Alvin Bruney is a Technology
Specialist working for Royal
o start off a project right, address accessibility in WPF is due to the fact that the new UI Automa-
Bank of Canada in the .NET
Centre of Excellence program.
He is a Microsoft Press author
and a long-time ASP.NET MVP.
T at the design level, even when overlooked in
the business requirements. Treat accessibility
as you would usability: neither is explicitly a busi-
tion handles accessibility support behind the scenes.
You can take advantage of this framework with new
projects and use the framework’s bridge and proxy
ness requirement, but both are required parts of a technology to extend existing projects’ feature sets.
successful user interface. Think about how users
can interact with your user interfaces and plan for UI Automation is more robust and exposes more
alternate accessibility with screen readers, magni- programmatic information to assistive technolo-
fiers, visual cues, keyboard usage, and so on. gies, allowing for an improved experience. You
can read more about UI Auto-
Another way to ensure acces- Fast Facts mation elsewhere in this mag-
sibility is to use the right devel- azine as well as at the MSDN®
opment tools. The good news
According to the U.S. Accessibility Developer Cen-
is that all versions of Visual President's Committee on ter. For now, I want to focus
Studio® address accessibility; Employment of People with on testing accessibility.
the bad news is that this sup- Disabilities, the majority of
port doesn’t guarantee perfect accommodations cost less
coverage, and you should in- than US$500, and many Testing WPF Applications
clude test and validation tools
have little or no cost at
in your development arsenal. When you build WPF applica-
Once you’ve got your design
all. However, the average tions, you can test accessibil-
in place and you’ve built what recruiting cost equals ity support using tools such as
you believe to be an accessible more than 13 percent of an Jaws, UI Spy, Windows-Eyes,
application, control, Web page, employee's annual salary. and ZoomText to name a few.
or service, you can use these There’s even an accessibil-
tools to test your deliverables ity checker, shown in Figure 1,
for compliance with accessibility requirements. on the Visual Studio tools menu for applications
based on Web site project templates. This tool ana-
In this article, I’ll talk about lyzes Web pages against Web Content Accessibility
these issues with respect to Win- Guidelines (WCAG) and Section 508 of the U.S.
Treat accessibility dows® Presentation Foundation Rehabilitation Act.
as you would usability: (WPF). I’ll also touch on some
areas where current offerings A strategy that I recommend is to use a combi-
neither is explicitly a from adaptive technology ven- nation of tools so that you can achieve great-
business requirement, dors present challenges to both er accessibility testing coverage. For instance,
users and developers. the Accessibility Checker in Visual Studio tar-
but both are gets Web pages; UI Spy targets UI Automa-
required parts of a tion compliance; AccChecker targets Microsoft®
successful user interface. WPF Has Accessibility Active Accessibility® compliance and general acces-
Built In sibility testing. You can decide which tool is a better
fit based on your needs and the underlying acces-
sibility framework you’re using. You might use UI
When you build a WPF application, you still need Spy and UIA Verify for testing WPF applications
to design for accessibility; however, it’s an easier based on UI Automation and Accessibility Checker
road to travel today because of the new accessible for those based on Microsoft Active Accessibility.
technology framework that you can build on.
Bear in mind that none of these tools help with
One reason for the increased accessibility support designing accessibility into your applications. They
WPF supports legacy Win32 controls with the Hwnd- Users with visibility impairments use programs like
Host control, providing an easier migration path from ZoomText to read content on screen. ZoomText, created
Win32 to XAML-based applications. However, there’s by Ai Squared, is a screen reader-magnifier for Microsoft
Figure 1: The accessibility checker in Visual Studio 2008 analyzes Web pages and displays results.
Windows. In some instances, the part of the magnified fier that supports UI Automation. Today, the choices
Expanding Law screen on a WPF native application may completely dis- available are pretty close to nil. The situation is expect-
appear or become unreadable as in Figure 2. ed to improve as ATVs start supporting WPF, UI Auto-
On October 2, 2007, National
mation, and other standard accessibility technologies.
Federation of the Blind (NFB)
This happens because the hardware-accelerated WPF
v. Target Corporation was rendering bypasses the software rendering layer. While A second option is to disable hardware acceleration
certified as a class action you can avoid this in general either by turning off hard- for Microsoft Windows in the dialog shown in Figure
lawsuit. The plaintiff, NFB, ware acceleration or by using the Magnification API, 3. Hardware acceleration uses DirectX® to improve
alleges that the Target.com the latter option is not available with the ZoomText video and animation quality. When you disable hard-
Web site violates the rights application. It’s important to note that while this is not ware acceleration, DirectX is not used.
of the disabled because strictly a WPF issue, the end result is that WPF-based
some parts of the site are applications may be inaccessible to ZoomText.
inaccessible to the visually Hardware Refreshes
impaired. Unfortunately, the workarounds are not particularly
The case raises eyebrows as pleasant. One option is to use another screen magni- Another accessibility issue may arise particularly in
the workplace with hardware refreshes. Periodically,
the first accessibility-based
the computers or workstations that employees use
class action lawsuit to target a
are upgraded in a hardware refresh cycle, includ-
public facing Web site owned
ing new monitors. While applications built on WPF
by a non-federal entity. These
technology will automatically scale correctly to fit
lawsuits have tended to target
the increased screen resolution, legacy-based con-
government institutions.
trols may not scale as you expect.
If NFB prevails, the mandate
for and scope of accessibility Some common controls such as the WPF dialog box
requirements may apply to are not WPF native. Instead, they are simply wrappers
all Web pages. But, as I have around legacy Win32 technology. Usually, issues with
shown you in this article, these controls manifest themselves in any number of
there are proactive steps ways, from controls with chopped or unreadable text
that IT organizations can to controls that do not maintain their layout integrity
take to comply with these under different screen conditions, such as the DPI
requirements. changes and high contrast mode in Figure 4.
ADVERTISING INDEX
Advertisers Index
Active Software Professionals VFP Conversion
www.aspalliance.com 6 www.VFPConversion.com 31
Aspose Xiine
www.aspose.com 75 www.xiine.com 69
Code Magazine
www.code-magazine.com 7
Developer Express
www.devexpress.com 2
Advertising Sales:
DevMavens Lake Quincy Media LLC
www.devmavens.com 15 330-677-2440
ssmith@lakequincy.com
msmith@lakequincy.com
EPS Software Corp.
www.eps-software.com 54, 60 Sales Managers
Erna Egger
Microsoft +43 (664) 151 0861
www.microsoft.com/enable/ 5 This listing is provided as a courtesy to our readers and erna@code-magazine.com
advertisers. Tammy Ferguson
Tech Conferences The publisher assumes no responsibility for errors 832-717-4445 ext 26
www.devconnections.com 41 or omissions. tammy@code-magazine.com
Writing a UI Automation
Provider for a Win32-based
Custom Control
Do you have a complex custom control that you want to make
programmatically accessible, but you aren’t sure how? Custom controls,
Brendan McKeon by their nature, tend to be very diverse: each is typically written for a specific
purpose, making it difficult to generalize implementation details. How do you
Brendan is a senior software
development engineer in the
know what to implement? You should consider supporting accessibility for any
Windows division. He’s worked custom control that performs its own rendering and input management—routing
at Microsoft for 10 years and mouse and keyboard input—within the HWND that it owns.
was a key senior contributor to
UI Automation.
n this article, I walk through the steps you need to providers expose information about the UI as a tree of
Listing 2: The WM_GETOBJECT message ensures UI Automation can access an instance of your provider.
LRESULT MyCustomControlWndProc(HWND hwnd, UINT uMsg, lParam, pProvider);
WPARAM wParam, LPARAM lParam) pProvider->Release();
{ return lres;
switch(uMsg) }
{ }
case WM_GETOBJECT: return DefWindowProc(hwnd, uMsg, wParam, lParam);
{ }
MyCustomControlProvider * pProvider =
new MyCustomControlProvider();
LRESULT lres = UiaReturnRawElement(hwnd, wParam,
IFACEMETHODIMP MyCustomControlProvider::
Patterns are interfaces that UI Automation uses
GetPropertyValue(PROPERTYID idProp,
to expose control-specific functionality such as
VARIANT * pRetVal )
selection or command invocation. I’ll revisit {
them later, so I’ll set the return value to NULL pRetVal->vt = VT_EMPTY;
here: if(idProp == UIA_NamePropertyId)
{
IFACEMETHODIMP MyCustomControlProvider:: pRetVal->bstrVal = SysAllocString(L“MyControlName“);
GetPatternProvider(PATTERNID idPattern, pRetVal->vt = VT_BSTR;
IUnknown ** pRetVal ) }
{ else if(idProp == UIA_ControlTypePropertyId)
*pRetVal = NULL; {
pRetVal->lVal = UIA_ButtonControlTypeId;
return S_OK;
pRetVal->vt = VT_I4;
}
}
return S_OK;
The GetPropertyValue method handles element }
properties. UI Automation divides properties into
two categories: those related to a specific area of
functionality—for example, those dealing with se- Finally, get_HostRawElementProvider tells UI Au-
lection, which only apply to controls that manage tomation which HWND this control is associated
selection—and those that broadly apply to any el- with:
ement, including Name, Enabled, and Control
Type. This latter category of property is handled IFACEMETHODIMP get_HostRawElementProvider(
in the GetPropertyValue method. IRawElementProviderSimple ** pRetVal )
{
For now, I’m supplying suitable values for the return UiaHostProviderFromHwnd(_hwnd,
element’s Name and Control Type properties. pRetVal);
These are two of the more important properties, as }
screen readers typically read the name and type of
a control as focus changes, but I can support any Once you’ve implemented the class, you have to
number of properties later: ensure that UI Automation can actually access an
void MyCustomControlProvider::OnUIDisposed()
{
_pControl = NULL;
}
instance of it. This is done by handling the WM_ JECT message to see if the HWND supports UI Au-
GETOBJECT message in the window’s Window tomation, and uses the returned provider to obtain
Procedure, as shown in Listing 2. more properties.
In response to WM_GETOBJECT, I create and re- All this happens only on demand: it’s only when a
turn an instance of the provider to UI Automation client requests an object for this specific HWND
via the UiaReturnRawElement API from UIAuto- that the WM_GETOBJECT message is sent. Get-
mationCore.dll. Standard COM reference counting PropertyValue is called only when a client requests
rules apply: UiaReturnRawElement calls AddRef() a property.
internally to claim its own reference; so I call Re-
lease() when I’m done with the WndProc’s refer-
ence. Connecting a Provider to Real Control
Data
Also, the code here creates a new instance of the
provider each time: this is allowable, as is creating a To make this example more realistic, I’m going to
single instance the first time and caching that value modify the provider code to contain a reference to
for later reuse. Just remember to use the Release() the custom control’s own data so that it can return
method on that reference in the WM_DESTROY real data from GetPropertyValue. Depending on
handler. how your control works, this might involve a pub-
lic or internal COM object, window messages, or
Note: Throughout this article, I refer to the Inspect direct access to the control’s data.
Objects tool, which is available in the Active Ac-
cessibility 2.0 SDK Tools download on the Micro- An important issue to address here is that of pro-
soft Download Center (http://www.microsoft.com/ vider lifetime. UI Automation holds onto a refer-
downloads/details.aspx?familyid=3755582a-a707- ence to the control on behalf of clients, and clients
460a-bf21-1373316e13f0&displaylang=en). This tool are not required to release their references at any
helps you see what UI Automation sees. You can use particular point in time. This means that a provider
it to test and verify your provider implementations. can outlive its corresponding UI.
If I point the Inspect Objects tool at the custom con- One way to deal with this situation is to add an
trol, it should report the Name and Control Type “alive” flag to the provider and set it to a “dead”
that I’ve specified above. What’s happening here is state when the UI is no longer present. Further
that Inspect Objects asks UI Automation for the ob- incoming calls to the IRawElementProvider can
ject at a specified point on the screen. UI Automa- then check this flag and return the defined value
tion determines the HWND, sends a WM_GETOB- UIA_E_ELEMENTNOTAVAILABLE.
Brendan McKeon
Creating UI Automation
Client Applications
Sometimes an application needs to interact with the user
interface (UI) of a second application. The first application might
be a test application that drives the UI of the target to run through some
automated tests. It might describe the UI out loud, as an aid to users that
are blind. It might be a speech application that allows users to give vocal
Matthew Karr commands. In each of these cases, the application needs a way to inspect
Software Development and interact with the UI of the system and other running applications.
Engineer
Matthew Karr has been a
icrosoft® UI Automation is a tool for doing Automation enables programmatic access through
developer at Microsoft for 5
years, working on Automation
and Accessibility. He’s helped
ship UI Automation V1 and the
M just that. It provides an abstracted model
of the UI, and allows a client application
to both investigate and manipulate the UI of all
five components:
Creating the CUIAutomation Object Directly Obtaining UI Automation Elements UI Automation and
Threading
The heart of the new COM API is the IUIAuto- Once you have the UI Automation object, you can
mation interface, which lets clients get automa- discover the entire UI. The UI is modeled as a tree Because of the way UI
tion elements, register event handlers, create of automation elements (IUIAutomationElement Automation uses Windows
various helper objects, and access other helper interface objects), where each element represents messages, conflicts can occur
methods. a single piece of UI. The IUIAutomationElement when a client application
interface has methods relevant to all controls, such attempts to interact with its
To get started using UI Automation in your applica- as checking properties or setting focus. own UI on the UI thread. These
tion, do the following: conflicts can lead to very slow
The root element of the UI Automation tree is the performance or even cause the
1. Include Uiautomation.h in your project head- desktop. You can obtain this element by calling either application to stop responding.
ers. This header will bring in the other headers the IUIAutomation::GetRootElement or IUIAutom
that define the API. ation::GetRootElementBuildCache method. Each If you intend your client
2. Declare a global pointer to an IUIAutomation method retrieves an IUIAutomationElement inter- application to interact with all
interface. face pointer, from which you can search or navigate elements on the desktop—
3. Initialize COM. the rest of tree, as described later in this article. including its own UI—you
4. Create an instance of the CUIAutomation class should make all UI Automation
and retrieve the IUIAutomation interface in If you have screen coordinates—such as the cur- calls on a separate thread. This
your global pointer. sor position in this example—you can retrieve an recommendation also applies
IUIAutomationElement interface by calling the when your application locates
The following example function creates the object IUIAutomation::ElementFromPoint method. elements and uses control
instance and stores the retrieved interface address patterns.
in the global pointer g_pAutomation: To retrieve an IUIAutomationElement interface
It is safe to make UI
from a window handle (HWND), call the IUIAuto
Automation calls within a UI
HRESULT InitializeUIAutomation() mation::ElementFromHandle method.
Automation event handler
{
because the event handler is
CoInitialize(NULL); You can retrieve an IUIAutomationElement inter-
face that represents the focused control by calling
never called on a UI thread.
HRESULT hr = However, when subscribing to
the IUIAutomation::GetFocusedElement method.
CoCreateInstance(__uuidof(CUIAutomation), events that may originate from
NULL, CLSCTX_INPROC_SERVER, your client application’s UI, you
__uuidof(IUIAutomation), must make the call on a non-UI
UI Automation Properties for Clients
(void**)&g_pAutomation); thread. Remove event handlers
return (hr); Properties of IUIAutomationElement objects con- on the same thread.
} tain information about UI elements, usually controls.
HRESULT hr = if(SUCCEEDED(hr))
pElement->GetCurrentPatternAs(UIA_RangeValuePatternId, {
__uuidof(IUIAutomationRangeValuePattern), hr = pRangeVal->SetValue(max);
(void **)&pRangeVal); }
The properties of an element are generic to all ele- simple like the Invoke pattern, which lets clients
ments and not specific to a control type. Control pat- invoke a control. In contrast, the more compli-
terns, discussed later, expose control-specific proper- cated Value pattern supports getting and setting
ties. a control’s value, and then checking whether the
value is read-only.
UI Automation properties are read-only. To set prop-
erties of a control, you must use the methods of the You can obtain a control pattern by calling the
appropriate control pattern; for example, use the IUIAutomationElement::GetCurrentPattern or
IScrollProvider::Scroll method to change the posi- IUIAutomationElement::GetCurrentPatternAs
tion values of a scrolling window. method, or their cached versions. Once you get
a control pattern interface, use it as you would
To improve performance, you the element itself, either by directly calling control
can cache property values of pattern methods or by accessing control pattern
controls and control patterns properties.
Programmatic access when you retrieve elements.
provides the ability to imitate, The TurnItUp method in Listing 2 uses the Ran-
Some generic properties, and geValue pattern to set a control (such as a volume
through code, any interaction and all control pattern properties, slider) to its maximum value.
experience exposed by traditional are available as properties on
the IUIAutomationElement In addition to checking for errors when getting
mouse and keyboard input. interface or control pattern the current pattern, this example also checks for
interface, and you can retrieve NULL because NULL is a valid return value when
them with accessor methods. a control does not support the pattern requested.
Automation core minimize cross-process calls and ticular name) is quite simple. However, conditions
improve searching time. The second is to use a tree can be considerably more complex.
walker to walk a UI tree.