共用方式為


如何從 UI 自動化提供者觸發事件

本主題包含範例程式代碼,示範Microsoft使用者介面自動化提供者如何引發事件。

下列範例程式代碼顯示實作自定義按鈕之應用程式的方法。 每當叫用自定義按鈕時,應用程式就會呼叫 方法。 方法會檢查是否有任何用戶端正在接收事件,如果有,則會觸發 UIA_Invoke_InvokedEventId 事件,以通知用戶端按鈕已被啟動。

// 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); 
    }
}

概念

UI 自動化事件概觀

How-To UI 自動化提供者的主題