Condividi tramite


Come restituire proprietà da un provider di Automazione interfaccia utente

Questo argomento contiene codice di esempio che illustra come un provider di Automazione interfaccia utente Microsoft restituisce le proprietà di un elemento dell'interfaccia utente alle applicazioni client.

Per recuperare un valore di proprietà dal provider, Automazione interfaccia utente chiama l'implementazione di un provider del metodo IRawElementProviderSimple::GetPropertyValue, passando l'ID della proprietà per recuperare e un puntatore a una struttura VARIANT. Se il provider supporta la proprietà specificata, copia il tipo di dati e il valore della proprietà nella struttura VARIANT . Se la proprietà non è supportata, il provider imposta il membro vt della struttura VARIANT su VT_EMPTY.

IFACEMETHODIMP Provider::GetPropertyValue(PROPERTYID propertyId, VARIANT* pRetVal)
{
    // The Name property is typically the same as the Caption property of the 
    // control window, if it has one. Here, the Name is overridden for the 
    // sake of illustration. 
    if (propertyId == UIA_NamePropertyId) 
    {
        pRetVal->vt = VT_BSTR;
        pRetVal->bstrVal = SysAllocString(L"Custom button");
    }
    
    else if (propertyId == UIA_ControlTypePropertyId) 
    {
        pRetVal->vt = VT_I4;
        pRetVal->lVal = UIA_ButtonControlTypeId; 
    }

    else if (propertyId == UIA_IsContentElementPropertyId) 
    {
        pRetVal->vt = VT_BOOL;
        pRetVal->lVal = TRUE; 
    }

    else if (propertyId == UIA_IsControlElementPropertyId) 
    {
        pRetVal->vt = VT_BOOL;
        pRetVal->lVal = TRUE; 
    }

    //
    // Return other properties as appropriate for the control type. 
    //

    else
    {
        pRetVal->vt = VT_EMPTY;
        // UI Automation will attempt to get the property from the  
        // provider for window that hosts the control.
    }
    return S_OK;
}

Informazioni concettuali

Cenni preliminari sulle proprietà di automazione interfaccia utente

Argomenti di procedura per i provider di Automazione interfaccia utente