复选框(选中或未选中)
Checkbox (checked or unchecked)
在使用自动化客户端时,我正在遍历 window 的所有元素。
我想要按钮...
[![在此处输入图片描述][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();
}
在使用自动化客户端时,我正在遍历 window 的所有元素。
我想要按钮...
[![在此处输入图片描述][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();
}