复选框(选中或未选中)



在使用自动化客户端时,我正在迭代窗口的所有元素。

我想得到按钮。。。

[![在此输入图像描述][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();
}

最新更新