c++ - 如何从元素中获取孩子?
问题描述
我有我的元素IUIAutomationElement elem
,现在我想得到它的孩子,
为此,我尝试遵循此代码
IUIAutomationElement* dummy = NULL; //creating a dummy
IUIAutomationElementArray* children_array; //creating an array
elem->GetCachedChildren(&children_array);
children_array->GetElement(0,&dummy);
qDebug() << dummy;
它不起作用,我得到未处理的异常。我哪里错了?
解决方案
我能够像这样解决它,我忘记设置真实条件,在这里GetCachedChildren()
我使用而不是使用FindAll()
,因为这更好地服务于目的。
IUIAutomationElementArray* children_array = NULL;
IUIAutomationElement* single_elem = nullptr;
TreeScope treeScope_1 = TreeScope::TreeScope_Children;
IUIAutomationCondition* Condition;
automation->CreateTrueCondition(&Condition);
HRESULT hs = elem->FindAll(treeScope_1, Condition, &children_array);
// HRESULT hs = elem->GetCachedChildren(&children_array);
if (SUCCEEDED(hs) && children_array != NULL) {
int number = 0;
children_array->get_Length(&number);
for (int i = 0;i < number;i++)
{
children_array->GetElement(i, &single_elem);
if (single_elem != NULL)
{
BSTR child_name = NULL;
hs = single_elem->get_CurrentName(&child_name);
if (SUCCEEDED(hs) && child_name != NULL)
{
std::wstring child_ws(child_name, SysStringLen(child_name));
QString child_qstring = QString::fromStdWString(child_ws);
global_ui->xml_scripts_textbox->addItem(child_qstring);
qDebug() << child_qstring;
}
SysFreeString(child_name);
}
single_elem = NULL;
}
SAFE_RELEASE(children_array);
}
```
推荐阅读
- linux - prometheus yml配置文件中如何配置特定IP?
- .net - 在 DateTime 中,仅使用了 64 位中的 62 位。负值不在规范中。我如何表示日期 BC?
- javascript - 使用 Javascript 以外的方式过滤数据
- android - Android Studio Fragment 将上下文传递给自定义 Gridview
- c# - mvc web api身份验证令牌cors问题
- jquery - 如何删除 datetimepicker 上的秒数?
- excel - 使用'LastRow''xlUp'时范围没有数据时如何防止行复制到另一个工作簿
- ruby-on-rails - 使用 Capistrano 和 NGinx 安装 RoR 应用程序后 Digital Ocean droplet 服务器超时
- java - Maven 不使用本地 JRE/JDK
- javascript - 删除字符串中的开始和结束斜杠的最佳方法是什么 - 如果存在 - 并使用 TypeScript/JavaScript 保留中间的斜杠