Retrieving Selected Objects and Children

[This is preliminary documentation and subject to change.]

By using the IAccessible::get_accSelection method, you effectively ask an object to retrieve information about any of its currently selected children. This method accepts the address of a single VARIANT structure, which it fills to represent the number of selected objects and indicate the type of information retrieved. After calling get_accSelection, you can use the value in the vt member to determine the call's result.

If one object is selected, then the application sets the vt member to VT_I4 or VT_DISPATCH. This value tells you whether to look for information in the form of a child ID or an IDispatch interface pointer, held in the lVal or pdispVal members, respectively. It is possible that the object you're working with has no children, but is selectable. In this case, vt will be VT_I4 and the lVal member will be CHILDID_SELF.

If multiple objects were selected, getting information about them is a little more complex. The server that handled your get_accSelection call sets the vt member to VT_UNKNOWN and the punkVal member to a valid IUnknown interface pointer. You can call this interface's QueryInterface method to request an IEnumVARIANT interface, which you can use to enumerate the selected objects. The IEnumVARIANT interface provides a method for enumerating a collection of variants, including heterogeneous collections of objects and intrinsic types. It is the server's responsibility to support this interface to allow you to enumerate the selected children. This is the preferred method.

Do not confuse selection with focus. Any or all objects in the system can simultaneously have selected children, but only one can have keyboard focus. For more information, see Accessible Object Selection and Focus and Retrieving the Object with Keyboard Focus.