// Gets the windows handle of an individual tab in a Windows Forms control
        private IntPtr GetItemHwndByIndex()
        {
            // On Win32 Tab controls the table page is parented by the dialog box not the
            // Tab control.
            IntPtr hwndParent = _hwnd;

            if (!_fIsWinform)
            {
                hwndParent = Misc.GetParent(hwndParent);
            }

            if (hwndParent != IntPtr.Zero)
            {
                // Get the tab name and match it with the window title of one of the children
                string sName = WindowsTabItem.GetName(_hwnd, _item, true);

                // If there is no tab name there is no way to match to one of the childrens window title.
                if (!string.IsNullOrEmpty(sName))
                {
                    return(Misc.FindWindowEx(hwndParent, IntPtr.Zero, null, sName));
                }
            }

            return(IntPtr.Zero);
        }
        // if all the tab items have no name then the control is not useful
        internal static bool IsValidControl(IntPtr hwnd)
        {
            for (int i = 0, c = GetItemCount(hwnd); i < c; i++)
            {
                if (!string.IsNullOrEmpty(WindowsTabItem.GetName(hwnd, i, true)))
                {
                    return(true);
                }
            }

            return(false);
        }
        private bool IsTabPage(IntPtr hwnd, out IntPtr hwndTab, out int item)
        {
            hwndTab = IntPtr.Zero;
            item    = -1;

            if (!SafeNativeMethods.IsWindowVisible(hwnd))
            {
                return(false);
            }

            try
            {
                if (!HasTabPageStyle(hwnd))
                {
                    return(false);
                }
            }
            catch (ElementNotAvailableException)
            {
                // if the received an ElementNotAvailableException this hwnd can not be a
                // tab page so return false.
                return(false);
            }

            string dlgName = Misc.ProxyGetText(hwnd);

            // if the dialog does not have a title there is no way to match to a tab item.
            if (string.IsNullOrEmpty(dlgName))
            {
                return(false);
            }

            IntPtr hwndParent = Misc.GetParent(hwnd);

            if (hwndParent == IntPtr.Zero)
            {
                return(false);
            }

            hwndTab = Misc.FindWindowEx(hwndParent, IntPtr.Zero, "SysTabControl32", null);
            // if the tab control is invisible then the tab control is not there.
            if (hwndTab == IntPtr.Zero || !SafeNativeMethods.IsWindowVisible(hwndTab))
            {
                return(false);
            }

            item = WindowsTabItem.GetCurrentSelectedItem(hwndTab);
            return(dlgName.Equals(WindowsTabItem.GetName(hwndTab, item, true)));
        }
        //------------------------------------------------------
        //
        //  Interface IRawElementProviderHwndOverride
        //
        //------------------------------------------------------
        IRawElementProviderSimple IRawElementProviderHwndOverride.GetOverrideProviderForHwnd(IntPtr hwnd)
        {
            // return the appropriate placeholder for the given hwnd...
            // loop over all the tabs to find it.

            string sTitle = Misc.ProxyGetText(hwnd);

            // If there is no hwnd title there is no way to match to the tab item.
            if (string.IsNullOrEmpty(sTitle))
            {
                return(null);
            }

            for (int i = 0, c = GetItemCount(_hwnd); i < c; i++)
            {
                if (sTitle == WindowsTabItem.GetName(_hwnd, i, true))
                {
                    return(new WindowsTabChildOverrideProxy(hwnd, CreateTabItem(i), i));
                }
            }

            return(null);
        }