Iaccessible:: get for this_ The accname method retrieves the name of the specified object. All objects support this property.
Syntax
HRESULT get_accName( [in] VARIANT varChild, [out, retval] BSTR *pszName );
Parameters
[in] varChild
Type: VARIANT
Specifies whether the retrieved name belongs to the object or one of the child elements of the object. This parameter is CHILDID_SELF (get information about the object) or child ID (get information about the child elements of the object) Of VARIANT structure For more information, see How to use child ID S in parameters.
[out, retval] pszName
Type: BSTR*
The address of the BSTR that receives the string containing the specified object name.
Return value
Type: HRESULT
If successful, s is returned_ OK.
If unsuccessful, one of the values in the following table or another criterion is returned COM error code . The server returns these values, but the client must always check the output parameters to ensure that they contain valid values. For more information, see Check the IAccessible return value.
error | describe |
---|---|
S_FALSE | The specified object does not have a name. |
E_INVALIDARG | Invalid parameter. |
Remarks
Many objects, such as icons, menus, check boxes, combo boxes, and other controls, have labels that are displayed to the user. Any labels that are displayed to the user are used for the object's name property. For more information, see Name attribute.
Note to server developers: if you use menu or button text for the Name property, remove all and numbers (&) that mark keyboard access keys. Provide the client with an access key to respond IAccessible::get_accKeyboardShortcut.
Localize the string returned from this property.
Server example
The following example shows a possible implementation of this method for managing custom list box controls for their own child elements.
// m_pStdAccessibleObject is the standard object returned by CreateStdAccessibleObject. // m_pControl is the control object that provides this accessibility object. It maintains // a zero-based collection of child items. HRESULT STDMETHODCALLTYPE AccServer::get_accName( VARIANT varChild, BSTR *pszName) { if (varChild.vt != VT_I4) //Must be VT_I4 type { *pszName = NULL; return E_INVALIDARG; } // For the control itself, let the standard accessible object return the name // assigned by the application. This is either the "caption" property or, if // there is no caption, the text of any label. if (varChild.lVal == CHILDID_SELF) { return m_pStdAccessibleObject->get_accName(varChild, pszName); } // Else return the name of the item in the list. else { CustomListControlItem* pItem = m_pControl->GetItemAt(varChild.lVal - 1); if (pItem) { *pszName = SysAllocString(pItem->GetName()); } } return S_OK; };
Client example
The following example function displays the accessible name of the control.
HRESULT PrintName(IAccessible* pAcc, long childId) { if (pAcc == NULL) { return E_INVALIDARG; } BSTR bstrName; VARIANT varChild; varChild.vt = VT_I4; //Must be VT_I4 type varChild.lVal = childId; HRESULT hr = pAcc->get_accName(varChild, &bstrName); printf("Name: %S ", bstrName); SysFreeString(bstrName); return hr; }
requirement
Minimum supported client | Windows 2000 Professional [desktop applications only] |
Minimum supported server | Windows Server 2003 [desktop applications only] |
Target platform | window |
title | oleacc.h |
library | oleacc.lib |
Dynamic link library | oleacc.dll |
Reissue | Active Accessibility 1.3 RDK on Windows NT 4.0 SP6 and later and Windows 95 |