다음을 통해 공유


서버측 UI 자동화 공급자 노출

참고참고

이 문서는 System.Windows.Automation 네임스페이스에 정의된 관리되는 UI Automation 클래스를 사용하려는 .NET Framework 개발자를 위해 작성되었습니다.UI Automation에 대한 최신 정보는 Windows Automation API: UI Automation을 참조하십시오.

이 항목에는 System.Windows.Forms.Control 창에서 호스팅되는 서버 쪽 UI 자동화 공급자를 노출하는 방법을 보여 주는 예제 코드가 나와 있습니다.

이 예제에서는 클라이언트 응용 프로그램이 창 정보를 요청할 때 UI Automation 핵심 서비스에 의해 전송되는 메시지인 WM_GETOBJECT를 트래핑하도록 창 프로시저를 재정의합니다.

예제

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

참고 항목

개념

UI 자동화 공급자 개요

서버측 UI 자동화 공급자 구현