Compartir a través de


Exponer un proveedor de UI Automation en el servidor

NotaNota

Esta documentación está dirigida a desarrolladores de .NET Framework que desean usar las clases administradas de UI Automation definidas en el espacio de nombres System.Windows.Automation.Para obtener información actualizada sobre UI Automation, vea Windows Automation API: UI Automation.

Este tema contiene código de ejemplo que muestra cómo exponer un proveedor de Automatización de la interfaz de usuario de servidor que se hospeda en una ventana System.Windows.Forms.Control.

En el ejemplo se invalida el procedimiento de ventana para interceptar WM_GETOBJECT, que es el mensaje enviado por el servicio principal de UI Automation cuando una aplicación cliente solicita información sobre la ventana.

Ejemplo

    ''' <summary>
    ''' Handles WM_GETOBJECT message; others are passed to base handler.
    ''' </summary>
    ''' <param name="m">Windows message.</param>
    ''' <remarks>
    ''' This method enables UI Automation to find the control.
    ''' In this example, the implementation of IRawElementProvider is in the same class
    ''' as this method.
    ''' </remarks>
    Protected Overrides Sub WndProc(ByRef m As Message)
        Const WM_GETOBJECT As Integer = &H3D

        If m.Msg = WM_GETOBJECT AndAlso m.LParam.ToInt32() = AutomationInteropProvider.RootObjectId Then
            m.Result = AutomationInteropProvider.ReturnRawElementProvider(Me.Handle, m.WParam, m.LParam, DirectCast(Me, IRawElementProviderSimple))
            Return
        End If
        MyBase.WndProc(m)

    End Sub 'WndProc

/// <summary>
/// Handles WM_GETOBJECT message; others are passed to base handler.
/// </summary>
/// <param name="m">Windows message.</param>
/// <remarks>
/// This method enables UI Automation to find the control.
/// In this example, the implementation of IRawElementProvider is in the same class
/// as this method.
/// </remarks>
protected override void WndProc(ref Message m)
{
    const int WM_GETOBJECT = 0x003D;

    if ((m.Msg == WM_GETOBJECT) && (m.LParam.ToInt32() == 
        AutomationInteropProvider.RootObjectId))
    {
        m.Result = AutomationInteropProvider.ReturnRawElementProvider(
                this.Handle, m.WParam, m.LParam, 
                (IRawElementProviderSimple)this);
        return;
    }
    base.WndProc(ref m);
}

Vea también

Conceptos

Información general sobre proveedores de UI Automation

Implementación del proveedor de UI Automation en el servidor