How to Raise Events from a UI Automation Provider
This topic contains example code that shows how a Microsoft UI Automation provider raises an event.
The following example code shows a method from an application that implements a custom button. The application calls the method whenever the custom button is invoked. The method checks whether any clients are listening for events and, if so, raises the UIA_Invoke_InvokedEventId event to notify the clients that the button was invoked.
// Responds to a button click. The source of the click could
// be the mouse, the keyboard, or a client's call to
// IUIAutomationInvokePattern::Invoke.
void CustomButton::InvokeButton(HWND hwnd)
{
// TODO: Perform program actions invoked by the control.
// Check whether any clients are listening for UI Automation
// events.
if (UiaClientsAreListening())
{
// Raise an Invoked event. GetUIAutomationProvider is an
// application-defined method that returns a pointer to
// the application's IRawElementProviderSimple interface.
UiaRaiseAutomationEvent(
GetUIAutomationProvider(hwnd), UIA_Invoke_InvokedEventId);
}
}
Related topics