gpt4 book ai didi

windows - 复选框(选中或未选中)

转载 作者:行者123 更新时间:2023-12-04 07:28:59 30 4
gpt4 key购买 nike

在使用自动化客户端时,我正在迭代窗口的所有元素。
我想得到按钮...
[![在此处输入图像描述][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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com