CUIAutomation ist im Grunde eine Klasse für die Arbeit mit dem CUIAutomation-Objekt, das IUIAutomationFocusChangedEventHandler und IUIAutomationEventHandler
implementiert
Code: Select all
CUIAutomation::CUIAutomation()
{
HRESULT hr = S_OK;
hr = pAutomation_.CoCreateInstance(__uuidof(CUIAutomation), NULL, CLSCTX_INPROC_SERVER);
pAutomation_->CreateCacheRequest(&propertyCache_);
propertyCache_->AddProperty(UIA_NamePropertyId);
propertyCache_->AddProperty(UIA_ControlTypePropertyId);
propertyCache_->AddProperty(UIA_IsPasswordPropertyId);
propertyCache_->AddProperty(UIA_ProcessIdPropertyId);
propertyCache_->AddProperty(UIA_AutomationIdPropertyId);
propertyCache_->put_AutomationElementMode(AutomationElementMode_None);
hr = EnableEvents();
}
Zum Beispiel schlägt der folgende Code fehl.
Code: Select all
HRESULT STDMETHODCALLTYPE CUIAutomation::QueryInterface(REFIID riid, void** ppInterface)
{
if (riid == __uuidof(IUnknown))
*ppInterface = static_cast(this);
else if (riid == __uuidof(IUIAutomationFocusChangedEventHandler))
*ppInterface = static_cast(this);
else if (riid == __uuidof(IUIAutomationEventHandler))
*ppInterface = static_cast(this);
else
{
*ppInterface = NULL;
return E_NOINTERFACE;
}
this->AddRef();
return S_OK;
}
HRESULT STDMETHODCALLTYPE CUIAutomation::HandleFocusChangedEvent(IUIAutomationElement *sender)
{
HRESULT hr = S_OK;
controlTypeId_ = 0;
isPassword_ = FALSE;
processId_ = 0;
logged_ = false;
// these work
sender->get_CachedControlType(&controlTypeId_);
sender->get_CachedIsPassword(&isPassword_);
sender->get_CachedProcessId(&processId_);
sender->get_CachedName(&name_);
sender->get_CachedAutomationId(&automationId_);
if (watchedElement_ == NULL)
{
PROPERTYID watchedProperties_[] = { UIA_ControlTypePropertyId };
if (automationId_ == "urlbar-input")
{
// this returns E_POINTER
hr = pAutomation_->AddAutomationEventHandler(UIA_Text_TextChangedEventId, sender, TreeScope_Element, NULL, this);
if (SUCCEEDED(hr))
{
watchedElement_ = sender;
}
}
}
return S_OK;
}
Ich habe das gleiche Problem mit AddPropertyChangedEventHandler
Es werden nur zwei Zeiger an AddAutomationEventHandler übergeben – sender und this.
UPDATE – Unter Debugger kann ich bestätigen, dass dies gültig ist und QueryInterface wird aufgerufen und ein gültiger IUIAutomationEventHandler* zurückgegeben.
Code: Select all
sender
Mobile version