Вы можете сделать это с помощью UIAComWrapper, вам понадобится ручка для этого окна (откуда вы пытаетесь скопировать) и информацию об этом элементе, которую вы можете получить от UIAutomationVerify.
var elementCollection = AutomationElement.FromHandle(windowHandle).FindAll(TreeScope.Subtree, Condition.TrueCondition);
foreach (var item in elementCollection)
{
//check item properties if element is the one you looking for
}
Кроме того, вместо Condition.TrueCondition
вы можете предоставить более сложный фильтр, чтобы получить только то, что один элемент.
Редактировать, добавил реальный пример:
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
const string InternetExplorerClass = "IEFrame";
static void Main()
{
var windowHandle = new IntPtr(0);
//Find internet explorer instance
windowHandle = FindWindow(InternetExplorerClass, null);
if (!windowHandle.Equals(IntPtr.Zero))
{
//create filter to improve search speed
var localizedControlType = new PropertyCondition(
AutomationElement.LocalizedControlTypeProperty,
"tab item");
//get all elements in internet explorer that match our filter
var elementCollection =
AutomationElement.FromHandle(windowHandle)
.FindAll(TreeScope.Subtree, localizedControlType);
//iterate through search results
foreach (AutomationElement item in elementCollection)
{
Console.WriteLine(item.Current.Name);
}
}
else
{
Console.WriteLine("Internet explorer not found");
}
Console.ReadLine();
}
Код выше будет найти Internet Explorer и будет печатать все вкладки названия на консоли. Я поместил исходный код в GitHub.
Благодарим вас за руководство. it className: AfxOleControl42. Ctrl + Shift + End не работает в этом приложении. Есть ли другой способ? –
Уважаемый cyberj0g Я изучаю вашу идею. Спасибо за это. –
Почему мой InputSimulator имеет только Equals и RefrenceEquals и не использует SimulateKeyDown или другие методы? –