Sdílet prostřednictvím


Vystavení zprostředkovatele automatizace uživatelského rozhraní na straně serveru

Poznámka:

Tato dokumentace je určená pro vývojáře rozhraní .NET Framework, kteří chtějí používat spravované třídy model UI Automation definované v System.Windows.Automation oboru názvů. Nejnovější informace o model UI Automation najdete v tématu Rozhraní API služby Windows Automation: model UI Automation.

Toto téma obsahuje ukázkový kód, který ukazuje, jak vystavit poskytovatele model UI Automation na straně serveru hostovaného v System.Windows.Forms.Control okně.

Příklad přepíše proceduru okna tak, aby WM_GETOBJECT schytá, což je zpráva odeslaná službou model UI Automation core, když klientská aplikace požaduje informace o okně.

Příklad

/// <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) && ((int)(long)m.LParam ==
        AutomationInteropProvider.RootObjectId))
    {
        m.Result = AutomationInteropProvider.ReturnRawElementProvider(
                this.Handle, m.WParam, m.LParam,
                (IRawElementProviderSimple)this);
        return;
    }
    base.WndProc(ref m);
}
''' <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 CInt(CLng(m.LParam)) = AutomationInteropProvider.RootObjectId Then
        m.Result = AutomationInteropProvider.ReturnRawElementProvider(Me.Handle, m.WParam, m.LParam, DirectCast(Me, IRawElementProviderSimple))
        Return
    End If
    MyBase.WndProc(m)

End Sub

Viz také