//EnumWindows handler BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lparam) { try { CMWDiscovery* mwd = reinterpret_cast<CMWDiscovery*>(lparam); IAccessiblePtr pAccessibleObject; HRESULT hr = ::AccessibleObjectFromWindow( hwnd, OBJID_WINDOW, __uuidof(IAccessible), (void**)&pAccessibleObject ); if( hr == S_OK ) { if( pAccessibleObject ) { _bstr_t bsName; VARIANT varChild; varChild.vt = VT_I4; varChild.lVal = CHILDID_SELF; if (SUCCEEDED(pAccessibleObject->get_accName(varChild, bsName.GetAddress()))) { CStdStringW name = bsName; CStdString::size_type iFind = name.rfind(mwd->m_name); if(iFind != CStdString::npos ) { mwd->m_hwnd = hwnd; return false; } } } } } catch(...) { //don't want this to stop the handler LOG_WS_ERROR(_T("Exception during EnumWindows")); } return true; }
// When a box is deleted, make the corresponding VwAccessRoot (if any) invalid. void VwAccessRoot::BoxDeleted(VwBox * pbox) { IAccessiblePtr qacc; if (ViewsGlobals::m_hmboxacc->Retrieve(pbox, qacc)) { ViewsGlobals::m_hmboxacc->Delete(pbox); dynamic_cast<VwAccessRoot *>(qacc.Ptr())->m_pbox = NULL; } }
// Get a dispinterface for the IAccessibility object for the specified box. void VwAccessRoot::GetAccessFor(VwBox * pbox, IDispatch ** ppdisp) { *ppdisp = NULL; if (!pbox) return; IAccessiblePtr qacc; // If we already made one for that box, answer it. Otherwise make one. if (!ViewsGlobals::m_hmboxacc->Retrieve(pbox, qacc)) qacc.Attach(NewObj VwAccessRoot(pbox)); qacc->QueryInterface(IID_IDispatch, (void **)ppdisp); }
static IAccessible2* IAccessible2FromIdentifier(int docHandle, int id) { IAccessiblePtr acc = NULL; VARIANT varChild; // WebKit returns a positive value for uniqueID, // but we need to pass a negative value when retrieving objects. id = -id; if (AccessibleObjectFromEvent((HWND)UlongToHandle(docHandle), OBJID_CLIENT, id, &acc, &varChild) != S_OK) return NULL; if (varChild.lVal != CHILDID_SELF) { // IAccessible2 can't be implemented on a simple child, // so this object is invalid. return NULL; } VariantClear(&varChild); IServiceProviderPtr serv = NULL; if (acc.QueryInterface(IID_IServiceProvider, &serv) != S_OK) return NULL; IAccessible2* pacc2 = NULL; serv->QueryService(IID_IAccessible, IID_IAccessible2, (void**)&pacc2); return pacc2; }