// Static Create method called by UIAutomation to create proxies for [....] controls. // returns null if unsuccessful internal static IRawElementProviderSimple Create(IntPtr hwnd, int idChild, int idObject) { // Currently there is an issue with CLR remoting that causes Accessible.CreateNativeFromEvent() to fail // for [....] controls. Until that is resolved use AccessibleObjectFromWindow() instead. It will // return a Native IAccessble and not a OleAcc implementaion. [....] does provide a Native IAccessible. Accessible acc = null; if (Accessible.AccessibleObjectFromWindow(hwnd, idObject, ref acc) != NativeMethods.S_OK || acc == null) { return(null); } switch (acc.Role) { // ============================================================ // WinformsSpinner controls are not identifiable by classname or // other simple properties. The following case calls the // WinformsSpinner constructor which in turn tries to establish // the class of the control as a fact or returns null. case AccessibleRole.Combobox: return(WinformsSpinner.Create(hwnd, idChild, idObject)); // ============================================================ case AccessibleRole.SpinButton: return(WindowsUpDown.Create(hwnd, idChild, idObject)); case AccessibleRole.Grouping: return(new WindowsButton(hwnd, null, WindowsButton.ButtonType.GroupBox, Misc.GetWindowStyle(hwnd) & NativeMethods.BS_TYPEMASK, acc)); case AccessibleRole.StatusBar: WindowsStatusBar sb = new WindowsStatusBar(hwnd, null, 0, acc); if (sb == null) { return(null); } return(idChild == NativeMethods.CHILD_SELF ? sb : sb.CreateStatusBarPane(idChild)); default: break; } return(null); }
// Static Create method called by UIAutomation to create proxies for [....] controls. // returns null if unsuccessful internal static IRawElementProviderSimple Create(IntPtr hwnd, int idChild, int idObject) { // Currently there is an issue with CLR remoting that causes Accessible.CreateNativeFromEvent() to fail // for [....] controls. Until that is resolved use AccessibleObjectFromWindow() instead. It will // return a Native IAccessble and not a OleAcc implementaion. [....] does provide a Native IAccessible. Accessible acc = null; if (Accessible.AccessibleObjectFromWindow(hwnd, idObject, ref acc) != NativeMethods.S_OK || acc == null) { return null; } switch (acc.Role) { // ============================================================ // WinformsSpinner controls are not identifiable by classname or // other simple properties. The following case calls the // WinformsSpinner constructor which in turn tries to establish // the class of the control as a fact or returns null. case AccessibleRole.Combobox: return WinformsSpinner.Create( hwnd, idChild, idObject ); // ============================================================ case AccessibleRole.SpinButton: return WindowsUpDown.Create( hwnd, idChild, idObject ); case AccessibleRole.Grouping: return new WindowsButton(hwnd, null, WindowsButton.ButtonType.GroupBox, Misc.GetWindowStyle(hwnd) & NativeMethods.BS_TYPEMASK, acc); case AccessibleRole.StatusBar: WindowsStatusBar sb = new WindowsStatusBar(hwnd, null, 0, acc); if (sb == null) { return null; } return idChild == NativeMethods.CHILD_SELF ? sb : sb.CreateStatusBarPane(idChild); default: break; } return null; }