Click here to Skip to main content
15,887,923 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 139K   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.Text.RegularExpressions;
using Accessibility;
using Office2007UIModel;
using MSAALayer;

namespace Office2007UIModel
{
    public class OfficeRibbon : OfficeUIItem
    {
        Dictionary<string, OfficeRibbonTab> _tabList = new Dictionary<string, OfficeRibbonTab>();

        public Dictionary<string, OfficeRibbonTab> Tabs
        {
            get{return _tabList;}
        }
        
        public OfficeRibbon(IAccessible parentAccObject, string name, bool ignoreInvisible)
            : base(parentAccObject, name, ignoreInvisible)
        {
            PopulateRibbonTabList();
        }

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

        private void PopulateRibbonTabList()
        {
            _tabList.Clear();

            foreach (var msaaUIItem in GetAllUIItemsOfType(AccessibleUIItemType.PageTab, true))
            {
                if (!string.IsNullOrEmpty(msaaUIItem.Properties.Name))
                {
                    _tabList.Add(msaaUIItem.Properties.Name, new OfficeRibbonTab(msaaUIItem.Accessible));
                }
            }
        }

        public void ReloadTabs()
        {
            PopulateRibbonTabList();
        }

    }
}

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