Click here to Skip to main content
15,897,187 members
Articles / Programming Languages / C#

UI Automation Using Microsoft Active Accessibility (MSAA)

Rate me:
Please Sign up or sign in to vote.
4.92/5 (46 votes)
11 Aug 2009CPOL4 min read 139.5K   4.9K   58  
This article describes a new way to automate window applications based on MSAA which otherwise is not possible using any other technique.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Accessibility;
using MSAALayer;

namespace Office2007UIModel
{
    public class OfficeToolBar : OfficeUIItem
    {
        Dictionary<string, OfficeUIItem> _controlList = new Dictionary<string, OfficeUIItem>();

        public Dictionary<string, OfficeUIItem> Controls
        {
            get
            {
                return _controlList;
            }
        }

        public OfficeToolBar(IAccessible accessibleObject)
            : base(accessibleObject)
        {
            PopulateControlList();
        }

        public OfficeToolBar(IAccessible parentAccObject, string name, bool ignoreInvisible)
            : base(parentAccObject, name, ignoreInvisible)
        {
            PopulateControlList();
        }

        public OfficeToolBar(IAccessible parentAccObject, string name, AccessibleUIItemType uiItemType, bool ignoreInvisible)
            : base(parentAccObject, name, uiItemType, ignoreInvisible)
        {
            PopulateControlList();
        }

        private void PopulateControlList()
        {
            _controlList.Clear();

            foreach (var msaaUIItem in GetChildren())
            {
                if (!string.IsNullOrEmpty(msaaUIItem.Properties.Name))
                {
                    _controlList.Add(msaaUIItem.Properties.Name, new OfficeUIItem(msaaUIItem.Accessible));
                }
            }
        }

        public void ReloadControls()
        {
            PopulateControlList();
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Proteans Software Solutions
India India
Currently, I am working with Proteans Software Solutions

Proteans a CAMO group company is an outsourcing company focusing on software product development and business application development on Microsoft Technology Platform. "Committed to consistently deliver high-quality software products and services through continual improvement of our knowledge and practices focused on increased customer satisfaction.

Before this, I started my Development career with Quark Media House Pvt. Ltd.

I have worked in various domains like Publishing, Document Management and Health Care.

I have gained experience in Development, Debugging, Bug fixing, Memory leak fixing and Performance Consultancy.

I am working on .NET technologies.

Comments and Discussions