VS2019 社区 vb .net - 类型 "AutomationElement" 未定义

VS2019 Community vb .net - type "AutomationElement" is not defined

我添加了对 UIAutomationTypes 和 UIAutomationClient 的引用 并使用这些导入

    Imports System.Windows.Automation
    Imports System.Runtime.InteropServices
    Imports System.Text

但是我得到一个错误: 未定义类型“AutomationElement” 当我使用该代码时

 Dim rootElement As AutomationElement = AutomationElement.FromHandle(hwnd)

怎么了?

好的 我不得不从文件中添加引用“UIAutomationClient”而不是从引用管理器中选择

设置引用后

  • UIAutomationClient
  • UIAutomationCore
  • UIAutomationCoreRes

全部在 uiautomationcore.dll 你可以在 vb .net

中做这样的事情
Imports System

Module Program

    Sub Main(args As String())
        Dim uiA As UIAutomationClient.CUIAutomation8 = New UIAutomationClient.CUIAutomation8
        Dim root As UIAutomationClient.IUIAutomationElement

        root = uiA.GetRootElement()

        Console.WriteLine("Hello World!" + root.CurrentClassName)
    End Sub
End Module

在 c# 中的完整示例

    using System;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            UIAutomationClient.CUIAutomation8 uia = new UIAutomationClient.CUIAutomation8();
            UIAutomationClient.IUIAutomationElement root;

            root = uia.GetRootElement();

            Console.WriteLine("Hello World!" + root.CurrentClassName);
        }
    }
}