AddFocusChangedEventHandler method
TOC
Collapse the table of content
Expand the table of content

IUIAutomation::AddFocusChangedEventHandler method

Registers a method that handles focus-changed events.

Note  Before implementing an event handler, you should be familiar with the threading issues described in Understanding Threading Issues.
 

Syntax


HRESULT AddFocusChangedEventHandler(
  [in] IUIAutomationCacheRequest             *cacheRequest,
  [in] IUIAutomationFocusChangedEventHandler *handler
);

Parameters

cacheRequest [in]

Type: IUIAutomationCacheRequest*

A pointer to a cache request, or NULL if no caching is wanted.

handler [in]

Type: IUIAutomationFocusChangedEventHandler*

A pointer to the object that handles the event.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

Focus-changed events are system-wide; you cannot set a narrower scope.

A UI Automation client should not use multiple threads to add or remove event handlers. Unexpected behavior can result if one event handler is being added or removed while another is being added or removed in the same client process.

Examples

The following example function creates an object that implements IUIAutomationFocusChangedEventHandler and subscribes to the event by adding the handler.


HRESULT AddFocusHandler(IUIAutomation* pAutomation)
{ 
    // CFocusHandler is a class that implements IUIAutomationFocusChangedEventHandler. 
    CFocusHandler* pFocusHandler = new CFocusHandler();
    if (!pFocusHandler)
    {
        return E_OUTOFMEMORY;
    }
    IUIAutomationFocusChangedEventHandler* pHandler;
    pFocusHandler->QueryInterface(IID_IUIAutomationFocusChangedEventHandler, (void**)&pHandler);
    HRESULT hr = pAutomation->AddFocusChangedEventHandler(NULL, pHandler);
    pFocusHandler->Release();
    return hr;
}


Requirements

Minimum supported client

Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista, Windows XP with SP3 and Platform Update for Windows Vista [desktop apps only]

Minimum supported server

Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008, Windows Server 2003 with SP2 and Platform Update for Windows Server 2008 [desktop apps only]

Header

UIAutomationClient.h (include UIAutomation.h)

IDL

UIAutomationClient.idl

See also

Reference
IUIAutomation
IUIAutomationFocusChangedEventHandler
RemoveAllEventHandlers
RemoveFocusChangedEventHandler
Conceptual
Caching UI Automation Properties and Control Patterns
Subscribing to UI Automation Events
Understanding Threading Issues

 

 

Show:
© 2016 Microsoft