ATGTestInput.Input.GetWindowHandleFromAutomationElement C# (CSharp) Method

GetWindowHandleFromAutomationElement() static private method

Gets WindowHandle from an AutomationElement
static private GetWindowHandleFromAutomationElement ( AutomationElement element ) : IntPtr
element System.Windows.Automation.AutomationElement
return System.IntPtr
        internal static IntPtr GetWindowHandleFromAutomationElement(AutomationElement element)
        {
            if( element == null )
                throw new ArgumentException("Automation Element cannot be null");

            object objHwnd = element.GetCurrentPropertyValue(AutomationElement.NativeWindowHandleProperty);
            IntPtr ptr = IntPtr.Zero;

            if (objHwnd is IntPtr)
                ptr = (IntPtr)objHwnd;
            else
                ptr = new IntPtr(Convert.ToInt64(objHwnd, CultureInfo.CurrentCulture));

            if (ptr == IntPtr.Zero)
                throw new InvalidOperationException("Could not get the handle to the element(window)");

            return ptr;
        }