public static AutomationElement FromIAccessible(Accessibility.IAccessible acc, int childId) { Utility.ValidateArgumentNonNull(acc, "acc"); try { UIAutomationClient.IUIAutomationElement element = Automation.Factory.ElementFromIAccessibleBuildCache( (UIAutomationClient.IAccessible)acc, childId, CacheRequest.CurrentNativeCacheRequest); return(AutomationElement.Wrap(element)); } catch (System.Runtime.InteropServices.COMException e) { Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; } } }
/// <summary> /// Used wherever we need a C# AccessibleObject for some child. Note that this is NOT /// a wrapper for the whole contents of the rootsite, so we do NOT want to make one /// with its IAccessible null, because that would turn around and retrieve the IAccessible /// for the whole rootsite. I think we could make one with rootsite null, except that we /// have an assertion to prevent that! So just return null if we don't actually have a /// related IAccessible to wrap. /// </summary> /// <param name="iAccessible"></param> /// <returns></returns> private AccessibleObject MakeRelatedWrapper(Accessibility.IAccessible iAccessible) { if (iAccessible == null) { return(null); } return(new AccessibilityWrapper(m_rootSite, iAccessible)); }
private void getAllChildren(SystemAccessibleObject[] childd) { counter++; Console.WriteLine(counter); foreach (SystemAccessibleObject dd in childd) { Accessibility.IAccessible test = dd.IAccessible; if (dd != null) { SystemAccessibleObject childOMine = new SystemAccessibleObject(test, 0); if (childOMine != null) { Console.WriteLine("ChildOMine name: " + childOMine.Name); } else { Console.WriteLine("childOOOO ist null"); } try { Console.WriteLine("aaaaaaaaaaaaaaaaaaaaaaaaaaaaa233423fhasdlfalsdfjaldsfjalsdfjaldsfjalsfjalfjdlsjfa"); Console.WriteLine("name : " + dd.Name + " loco:" + dd.Location + " mousepoint : X " + XKoordinate + " : Y " + YKoordinate); allChilds.Add(dd.Name + "LOCATION:" + dd.Location); SystemAccessibleObject[] kinder = dd.Children; if (kinder.Length != 0) { Console.WriteLine("-----------------------------------------------------------------"); getAllChildren(childOMine.Children); } } catch (Exception e) { Console.WriteLine(e.Message); } } else { break; } } }
public void IAccessibleInterop() { // Get the clock AutomationElement taskbar = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "Shell_TrayWnd")); Assert.IsNotNull(taskbar); AutomationElement clock = taskbar.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "TrayClockWClass")); Assert.IsNotNull(clock); // Get the IAccessible for the clock IntPtr clockHwnd = (IntPtr)clock.Current.NativeWindowHandle; Guid iidAccessible = new Guid("{618736E0-3C3D-11CF-810C-00AA00389B71}"); object obj = null; int retVal = AccessibleObjectFromWindow(clockHwnd, (uint)0xFFFFFFFC, ref iidAccessible, ref obj); Assert.IsNotNull(obj); Accessibility.IAccessible accessible = (Accessibility.IAccessible)obj; Assert.IsNotNull(accessible); Assert.AreEqual(0x3D /* clock */, accessible.get_accRole(0)); // Convert to an element AutomationElement element = AutomationElement.FromIAccessible(accessible, 0); Assert.IsNotNull(element); Assert.AreEqual(ControlType.Pane, element.Current.ControlType); // Round-trip: let's get the IAccessible back out LegacyIAccessiblePattern legacy = (LegacyIAccessiblePattern)element.GetCurrentPattern(LegacyIAccessiblePattern.Pattern); Accessibility.IAccessible legacyIAcc = legacy.GetIAccessible(); Assert.IsNotNull(legacyIAcc); Assert.AreEqual(0x3D /* clock */, legacyIAcc.get_accRole(0)); }
/// <summary> /// Make one. The root site is used in case comAccessible is null, to keep trying for a valid /// one later when the root box has been created. /// </summary> /// <param name="rootSite"></param> /// <param name="comAccessible"></param> public AccessibilityWrapper(SimpleRootSite rootSite, Accessibility.IAccessible comAccessible) : base(rootSite) { Debug.Assert(rootSite != null); m_rootSite = rootSite; m_comAccessible = comAccessible; }