Windows UI Accessibility API

Overview

The Windows UI Accessibility API provides developers with a set of interfaces and classes to make applications accessible to users with disabilities. It enables assistive technologies such as screen readers, magnifiers, and speech recognition to interact with UI elements programmatically.

Key Interfaces

Sample: Exposing a Custom Button

#include <windows.h>
#include <oleacc.h>

class MyButton : public IAccessible {
public:
    // IUnknown
    HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override {
        if (riid == __uuidof(IAccessible) || riid == IID_IUnknown)
            *ppvObject = static_cast<IAccessible*>(this);
        else {
            *ppvObject = nullptr;
            return E_NOINTERFACE;
        }
        AddRef();
        return S_OK;
    }
    ULONG STDMETHODCALLTYPE AddRef() override { return ++refCount; }
    ULONG STDMETHODCALLTYPE Release() override {
        if (--refCount == 0) { delete this; return 0; }
        return refCount;
    }

    // IAccessible
    HRESULT STDMETHODCALLTYPE get_accName(VARIANT varChild, BSTR *pszName) override {
        if (varChild.lVal == CHILDID_SELF) {
            *pszName = SysAllocString(L"Submit");
            return S_OK;
        }
        return E_INVALIDARG;
    }
    HRESULT STDMETHODCALLTYPE get_accRole(VARIANT varChild, VARIANT *pvarRole) override {
        if (varChild.lVal == CHILDID_SELF) {
            pvarRole->vt = VT_I4;
            pvarRole->lVal = ROLE_SYSTEM_PUSHBUTTON;
            return S_OK;
        }
        return E_INVALIDARG;
    }
    // Implement other methods as needed...
private:
    LONG refCount = 1;
};

Compile and register the COM object to make the button discoverable by assistive technologies.

Accessibility Patterns

PatternDescription
InvokeEnables a control to be invoked (e.g., button click).
SelectionAllows selection of items within a container.
ValueProvides a numeric or textual value of a control.
ExpandCollapseSupports expanding or collapsing a container.
ToggleRepresents a binary on/off state.

Testing Your UI

Use the following tools to verify accessibility compliance: