Önbellek Nasıl Kullanılır
Bu konu, Microsoft UI Otomasyonu ağacının önbelleğe alma (veya toplu getirme) özelliklerinin nasıl kullanılacağını gösteren örnek kod içerir. Aşağıdaki konular ele alınmaktadır:
- Özellikleri ve Denetim Desenlerini Önbelleğe Alma
- Önbellekten Özellikleri ve Denetim Kalıplarını Alma
- İlgili konular
Özellikleri ve Denetim Desenlerini Önbelleğe Alma
Aşağıdaki kod örneği, liste denetiminden öğeleri alan ve her öğe için SelectionItem denetim desenini ve Name özelliğini önbelleğe alan bir işlevi gösterir. Varsayılan olarak, liste öğeleri tam başvuruyla döndürülür, böylece tüm geçerli özellikler kullanılabilir durumda kalır.
// Given a list element, caches a control pattern and a property for
// all the list items.
IUIAutomationElementArray* FindAndCacheListItems(IUIAutomationElement* pList)
{
if (pList == NULL)
return NULL;
IUIAutomationCondition* pCondition = NULL;
IUIAutomationCacheRequest* pCacheRequest = NULL;
IUIAutomationElementArray* pFound = NULL;
HRESULT hr = g_pAutomation->CreateTrueCondition(&pCondition);
if (FAILED(hr))
goto cleanup;
hr = g_pAutomation->CreateCacheRequest(&pCacheRequest);
if (FAILED(hr))
goto cleanup;
hr = pCacheRequest->AddPattern(UIA_SelectionItemPatternId);
if (FAILED(hr))
goto cleanup;
hr = pCacheRequest->AddProperty(UIA_NamePropertyId);
if (FAILED(hr))
goto cleanup;
pList->FindAllBuildCache(TreeScope_Children, pCondition, pCacheRequest, &pFound);
cleanup:
if (pCondition != NULL)
pCondition->Release();
if (pCacheRequest != NULL)
pCacheRequest->Release();
return pFound;
}
Önbellekten Özellikleri ve Denetim Desenlerini Alma
Aşağıdaki kod, önbellekten özelliklerin ve denetim desenlerinin nasıl alınduğunu gösterir. Liste öğesi için SelectionItem denetim desenini ve Name özelliğini alır.
// Demonstrates retrieval of cached properties from a list item
// obtained in FindAndCacheListItems.
HRESULT GetCachedListItem(IUIAutomationElement* pItem)
{
if (pItem == NULL)
{
return E_INVALIDARG;
}
IUIAutomationSelectionItemPattern* pSelectionItemPattern;
HRESULT hr = pItem->GetCachedPatternAs(UIA_SelectionItemPatternId,
IID_IUIAutomationSelectionItemPattern, (void**)&pSelectionItemPattern);
if (pSelectionItemPattern != NULL)
{
// ... To do: Do something with the pattern.
pSelectionItemPattern->Release();
}
// Retrieve a cached property.
BSTR bstrName;
hr = pItem->get_CachedName(&bstrName);
if (SUCCEEDED(hr))
{
// ... To do: Do something with the property.
// Clean up when done with name.
SysFreeString(bstrName);
bstrName = NULL;
}
BOOL isControl;
// The following returns E_INVALIDARG because the property was not cached.
// hr = pItem->get_CachedIsControlElement(&isControl);
// The following is valid because we have a full reference to the object, therefore
// we can get current properties. If the cache request had been made with
// AutomationElementMode_None, no current properties would be available from
// this IUIAutomationElement.
hr = pItem->get_CurrentIsControlElement(&isControl);
return hr;
}
İlgili konular