Skip to content

Latest commit

 

History

History
69 lines (46 loc) · 3.07 KB

uiauto-howto-expose-serverside-uiautomation-provider.md

File metadata and controls

69 lines (46 loc) · 3.07 KB
title description ms.assetid ms.topic ms.date
How to Expose a Server-Side UI Automation Provider
This topic contains example code that shows how to expose a server-side Microsoft UI Automation provider for a custom control.
68bf16c7-fbab-478a-97be-47d1195028f3
article
05/31/2018

How to Expose a Server-Side UI Automation Provider

This topic contains example code that shows how to expose a server-side Microsoft UI Automation provider for a custom control.

Microsoft UI Automation sends the WM_GETOBJECT message to a provider application to retrieve information about an accessible object supported by the provider. UI Automation sends WM_GETOBJECT when a client calls IUIAutomation::ElementFromHandle, ElementFromPoint, and GetFocusedElement, and when handling events for which the client has registered.

When a provider receives a WM_GETOBJECT message, it should check whether the lParam parameter is equal to UiaRootObjectId. If it is, the provider should return the IRawElementProviderSimple interface of the object. The provider returns the interface by calling the UiaReturnRawElementProvider function.

The following example demonstrates shows how to respond to WM_GETOBJECT.

    // Expose the custom button's server-side provider to UI Automation.
    case WM_GETOBJECT:
        {
            // If lParam matches UiaRootObjectId, return IRawElementProviderSimple.
            if (static_cast<long>(lParam) == static_cast<long>(UiaRootObjectId))
            {
                // Retrieve the pointer to the custom button object from the
                // window data.
                CustomButton* pControl = reinterpret_cast<CustomButton*>(
                    GetWindowLongPtr(hwnd, GWLP_USERDATA));

                // Call an application-defined method to get the
                // IRawElementProviderSimple pointer.
                IRawElementProviderSimple* pRootProvider = 
                    pControl->GetUIAutomationProvider(hwnd);

                // Return the IRawElementProviderSimple pointer to UI Automation.
                return UiaReturnRawElementProvider(hwnd, wParam, lParam, 
                    pRootProvider);
            }
            return 0;
        }

Related topics

Conceptual

Implementing a Server-Side UI Automation Provider

The WM_GETOBJECT Message

How-To Topics for UI Automation Providers