作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在使用自动化客户端时,我正在迭代窗口的所有元素。
我想得到按钮...
[![在此处输入图像描述][1]][1]
这是代码...
如何在不通过另一个 UI 运行的情况下获取这 3 个属性值中的任何一个。
最佳答案
这是一些示例代码,如果运行 Discord,将打印“静音”按钮状态:
#include <windows.h>
#include <atlbase.h>
#include <atlcom.h>
#include <UIAutomationCore.h>
#include <UIAutomationClient.h>
int main()
{
// warning: error checks omitted!
CoInitializeEx(NULL, COINITBASE_MULTITHREADED);
{
// start UIA & get root
CComPtr<IUIAutomation> automation;
automation.CoCreateInstance(CLSID_CUIAutomation8);
CComPtr<IUIAutomationElement> root;
automation->GetRootElement(&root);
// find the "Discord" window
CComPtr<IUIAutomationCondition> discordCondition;
automation->CreatePropertyCondition(UIA_NamePropertyId, CComVariant(L"Discord"), &discordCondition);
CComPtr<IUIAutomationElement> discord;
root->FindFirst(TreeScope_Children, discordCondition, &discord);
// create a name="Mute" && type = button condition
CComPtr<IUIAutomationCondition> muteCondition;
automation->CreatePropertyCondition(UIA_NamePropertyId, CComVariant(L"Mute"), &muteCondition);
CComPtr<IUIAutomationCondition> buttonCondition;
automation->CreatePropertyCondition(UIA_ControlTypePropertyId, CComVariant(UIA_ButtonControlTypeId), &buttonCondition);
CComPtr<IUIAutomationCondition> andCondition;
automation->CreateAndCondition(muteCondition, buttonCondition, &andCondition);
// get "Mute" button
CComPtr<IUIAutomationElement> muteButton;
discord->FindFirst(TreeScope_Subtree, andCondition, &muteButton);
// get toggle pattern
CComPtr<IUIAutomationTogglePattern> toggle;
muteButton->GetCurrentPatternAs(UIA_TogglePatternId, IID_PPV_ARGS(&toggle));
// get toggle state
ToggleState state;
toggle->get_CurrentToggleState(&state);
switch (state)
{
case ToggleState_Off:
wprintf(L"state is off.\n");
break;
case ToggleState_On:
wprintf(L"state is on.\n");
break;
case ToggleState_Indeterminate:
wprintf(L"state is indeterminate.\n");
break;
}
}
CoUninitialize();
}
关于windows - 复选框(选中或未选中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68058309/
我是一名优秀的程序员,十分优秀!