Verfügbarmachen eines serverseitigen Benutzeroberflächenautomatisierungs-Anbieters

Aktualisiert: November 2007

Dieses Thema enthält Beispielcode, der zeigt, wie Sie einen serverseitigen Benutzeroberflächenautomatisierungs-Anbieter verfügbar machen, der in einem System.Windows.Forms.Control-Fenster gehostet wird.

Das Beispiel überschreibt die Fensterprozedur zum Trappen von WM_GETOBJECT, welches die Nachricht ist, die vom UI-Automatisierung-Basisdienst gesendet wird, wenn ein Client Informationen zum Fenster anfordert.

Beispiel

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

Siehe auch

Konzepte

Übersicht über die Benutzeroberflächenautomatisierungs-Anbieter

Implementierung eines serverseitigen Benutzeroberflächenautomatisierungs-Anbieters