// In the form load event, get all accessible tab objects and list them in // the lbTabs list box. private void RibbonInfoForm_Load(object sender, EventArgs e) { // Initialize the IAccessible interface of the top window. Globals.ThisAddIn.Application.Activate(); this.TopWindow = MSAAHelper.GetAccessibleObjectFromHandle( Process.GetCurrentProcess().MainWindowHandle); // Get the IAccessible object of the Ribbon property page. IAccessible ribbon = MSAAHelper.GetAccessibleObjectByNameAndRole( this.TopWindow, new Regex("Ribbon"), "property page", false); // Find all visible ribbon tabs and show them in the list box. IAccessible[] children = MSAAHelper.GetAccessibleChildren( MSAAHelper.GetAccessibleObjectByNameAndRole(ribbon, new Regex("Ribbon Tabs"), "page tab list", true)); foreach (IAccessible child in children) { if (child.accChildCount > 0) { IAccessible[] tabs = MSAAHelper.GetAccessibleChildren(child); foreach (IAccessible tab in tabs) { String state = MSAAHelper.GetStateText( (MSAAStateConstants)tab.get_accState(0)); if (!state.Contains("invisible")) { this.lbTabs.Items.Add(new ListBoxItem(tab.get_accName(0), tab)); } } } } }