// 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)); } } } } }
// When the btnListChildControls button is clicked, the code probes all // controls in the selected group and list them in the lbControls list box. private void btnListChildControls_Click(object sender, EventArgs e) { this.lbControls.Items.Clear(); // Find the selected group. ListBoxItem item = this.lbGroups.SelectedItem as ListBoxItem; if (item != null) { IAccessible group = MSAAHelper.GetAccessibleObjectByNameAndRole( this.TopWindow, new Regex(item.Name), "tool bar", true); if (group == null) { MessageBox.Show("Error: the " + item.Name + " group cannot be found"); return; } // Get the controls, and list the controls in the lbControls control. IAccessible[] controls = MSAAHelper.GetAccessibleChildren(group); foreach (IAccessible control in controls) { this.lbControls.Items.Add(new ListBoxItem(control.get_accName(0), control)); } } }