复选框(选中或未选中) [英] Checkbox (checked or unchecked)
本文介绍了复选框(选中或未选中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用自动化客户端时,我正在遍历窗口的所有元素.
我想要按钮...
[![在此处输入图片描述][1]][1]
这是代码...
<预><代码>如何在不运行其他 UI 的情况下获取这 3 个属性值中的任何一个.
解决方案
这里是一些示例代码,如果运行 Discord,将打印Mute"按钮状态:
#include #include #include #include #include int main(){//警告:省略错误检查!CoInitializeEx(NULL, COINITBASE_MULTITHREADED);{//启动 UIA &获得root权限CComPtr<IUIAutomation>自动化;自动化.CoCreateInstance(CLSID_CUIAutomation8);CComPtr根;自动化->GetRootElement(&root);//找到Discord"窗户CComPtr不和谐;自动化-> CreatePropertyCondition(UIA_NamePropertyId, CComVariant(LDiscord"), &discordCondition);CComPtr不和谐;root-> FindFirst(TreeScope_Children, discordCondition, &discord);//创建一个名称=静音"&&类型 = 按钮条件CComPtr静音状态;自动化-> CreatePropertyCondition(UIA_NamePropertyId, CComVariant(LMute"), &muteCondition);CComPtr按钮状态;自动化-> CreatePropertyCondition(UIA_ControlTypePropertyId, CComVariant(UIA_ButtonControlTypeId), &buttonCondition);CComPtr和条件;自动化-> CreateAndCondition(muteCondition, buttonCondition, &andCondition);//获取静音"按钮CComPtr静音按钮;不和谐-> FindFirst(TreeScope_Subtree, andCondition, &muteButton);//获取切换模式CComPtr切换;muteButton->GetCurrentPatternAs(UIA_TogglePatternId, IID_PPV_ARGS(&toggle));//获取切换状态ToggleState 状态;切换->get_CurrentToggleState(&state);开关(状态){案例 ToggleState_Off:wprintf(L状态关闭.\n");休息;案例 ToggleState_On:wprintf(L"state is on.\n");休息;案例 ToggleState_Indeterminate:wprintf(L"state is indeterminate.\n");休息;}}CoUninitialize();}
While using automation client I am iterating over all the elements of the window.
And I want to get button...
[![enter image description here][1]][1]
Here is code...
How can I get any of these 3 property values without running through another UI.
解决方案
Here is some sample code which, if Discord is ran, will print the "Mute" button state:
#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();
}
这篇关于复选框(选中或未选中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文