private IUIAutomationElement GetNearbyElement(GetElementDelegate getNextElement)
        {
            var currentElement = GetCurrentElement();

            if (currentElement == null)
            {
                return(null);
            }

            var treeWalker = A11yAutomation.GetTreeWalker(this.TreeViewMode);

            var retVal = getNextElement?.Invoke(treeWalker, currentElement);

            // make sure that we skip an element from current process while walking tree.
            // this code should be hit only at App level. but for sure.
            if (DesktopElement.IsFromCurrentProcess(retVal))
            {
                var tmp = retVal;

                retVal = getNextElement?.Invoke(treeWalker, retVal);

                // since element is not in use, release.
                Marshal.ReleaseComObject(tmp);
            }

            Marshal.ReleaseComObject(treeWalker);

            return(retVal);
        }
예제 #2
0
        /// <summary>
        /// Get instance of EventMessage
        /// when sender is null, it is generally error case.
        ///
        /// if it returns null, it means that the sender is hosted in the process of running Recorder code.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="sender"></param>
        /// <param name="comment"></param>
        /// <param name="isError"></param>
        /// <returns></returns>
        public static EventMessage GetInstance(int id, IUIAutomationElement sender)
        {
            if (sender == null || !DesktopElement.IsFromCurrentProcess(sender))
            {
                return(new EventMessage(id, sender));
            }

            return(null);
        }