我正在尝试获取下图中标记的LegacyIAccessible值:
到目前为止,我已经能够阅读这些:
#include <UIAutomation.h> // UIAutomation includes.
#include <UIAutomationCore.h>
#include <UIAutomationClient.h>
#include "Oleacc.h"
#include "atlbase.h"
#pragma comment(lib,"Oleacc.lib")
LPCWSTR Acc(HWND hwnd) {
CComPtr<IUIAutomation> pUIAutomation;
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(__uuidof(CUIAutomation), NULL, CLSCTX_INPROC_SERVER, __uuidof(IUIAutomation), (void**)&pUIAutomation);
if (SUCCEEDED(hr))
{
IUIAutomationElement* pRoot = NULL;
hr = pUIAutomation->ElementFromHandle(hwnd, &pRoot);
if (SUCCEEDED(hr))
{
IUIAutomationElementArray* pElementArray = nullptr;
IUIAutomationCondition* pCondition;
hr = pUIAutomation->CreateTrueCondition(&pCondition);
IUIAutomationElementArray* pEA;
IUIAutomationCacheRequest* pCacheRequest;
hr = pUIAutomation->CreateCacheRequest(&pCacheRequest);
pCacheRequest->AddProperty(UIA_NamePropertyId);
pCacheRequest->AddProperty(UIA_AutomationIdPropertyId);
pCacheRequest->AddProperty(UIA_LocalizedControlTypePropertyId);
//pCacheRequest->put_TreeScope((TreeScope)(TreeScope_Element | TreeScope_Descendants));
hr = pRoot->FindAllBuildCache(TreeScope_Descendants, pCondition, pCacheRequest, &pEA);
if (SUCCEEDED(hr))
{
int nNbItems = 0;
hr = pEA->get_Length(&nNbItems);
for (int nItem = 0; nItem <= nNbItems - 1; nItem++)
{
IUIAutomationElement* pElement = nullptr;
hr = pEA->GetElement(nItem, &pElement);
BSTR name;
pElement->get_CurrentName(&name);
UIA_HWND uia_hwnd = nullptr;
pElement->get_CurrentNativeWindowHandle(&uia_hwnd);
BSTR classname = nullptr;
pElement->get_CurrentClassName(&classname);
RECT rect;
pElement->get_CurrentBoundingRectangle(&rect);
pElement->Release();
}
}
pCacheRequest->Release();
pCondition->Release();
pRoot->Release();
}
//pUIAutomation->Release(); // <- needed?
}
CoUninitialize();
return (L"SUCCEEDED");
}
当我尝试呼叫:
DWORD CurrentState;
pElement->get_CurrentState(&CurrentState);
我得到这个错误:class "IUIAutomationElement" has no member "get_CurrentState"
.
我想我应该使用IUIAutomationLegacyIAccessiblePattern
,但我不知道如何正确地使用它重写函数。
另外,函数with
和without
'cache'之间有什么区别?
2条答案
按热度按时间rfbsl7qr1#
一个GetCurrentPatternAs的例子。不涉及缓存。
blmhpbnm2#
在Python中,可以通过以下方式使用
uiautomation.py
库找到控件后找到LegacyIAccessible
的名称和值:假设你已经找到了控件
elem_control
:Value
和Name
是LegacyIAccessiblePattern
类的属性。