IAccessible::get_accName method (oleacc.h)

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.

Return value
errordescribe

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 clientWindows 2000 Professional [desktop applications only]
Minimum supported serverWindows Server 2003 [desktop applications only]
Target platformwindow
titleoleacc.h
libraryoleacc.lib
Dynamic link libraryoleacc.dll
ReissueActive Accessibility 1.3 RDK on Windows NT 4.0 SP6 and later and Windows 95

Added by wilku on Mon, 13 Dec 2021 10:14:11 +0200