System.Windows.Automation.AutomationElement.FromHandle C# (CSharp) Method

FromHandle() public static method

public static FromHandle ( IntPtr hwnd ) : AutomationElement
hwnd System.IntPtr
return AutomationElement
        public static AutomationElement FromHandle(IntPtr hwnd)
        {
            Utility.ValidateArgument(hwnd != IntPtr.Zero, "Hwnd cannot be null");
            try
            {
                UIAutomationClient.IUIAutomationElement element =
                    Automation.Factory.ElementFromHandleBuildCache(hwnd, CacheRequest.CurrentNativeCacheRequest);
                return AutomationElement.Wrap(element);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
            }
        }

Usage Example

Example #1
0
        public Marker()
        {
            InitializeComponent();
            SetWindowLong(this.Handle, -20, GetWindowLong(this.Handle, -20)
                          | 0x20 | 0x80000 | 0x08000000); //TRANSPARENT,LAYERED,NOACTIVATE
            Rectangle ScrBnd = Screen.PrimaryScreen.Bounds;

            Location = new Point(ScrBnd.Right, ScrBnd.Bottom);
            Size     = ScrBnd.Size;
            ClearMarks();
            Location = new Point(0, 0);

            Nav = new CountedNavi(
                AutoElem.FromHandle(GetDesktopWindow())
                );
            Nav.Walker          = TreeWalker.ControlViewWalker;
            Nav.CurElemChanged += MarkElemInfo;

            RegHotkey(0, MK.Alt | MK.Control, Keys.Up);
            RegHotkey(1, MK.Alt | MK.Control, Keys.Down);
            RegHotkey(2, MK.Alt | MK.Control, Keys.Left);
            RegHotkey(3, MK.Alt | MK.Control, Keys.Right);
            RegHotkey(6, MK.Alt | MK.Control, Keys.D1);

            RegHotkey(7, MK.Alt | MK.Control, Keys.D2);
            RegHotkey(5, MK.Alt | MK.Control, Keys.Enter);
        }
All Usage Examples Of System.Windows.Automation.AutomationElement::FromHandle