+
+void MyFrame::OnQuery(wxCommandEvent& WXUNUSED(event))
+{
+ m_textCtrl->Clear();
+ IAccessible* accessibleFrame = NULL;
+ if (S_OK != AccessibleObjectFromWindow((HWND) GetHWND(), OBJID_CLIENT,
+ IID_IAccessible, (void**) & accessibleFrame))
+ {
+ Log(wxT("Could not get object."));
+ return;
+ }
+ if (accessibleFrame)
+ {
+ Log(wxT("Got an IAccessible for the frame."));
+ LogObject(0, accessibleFrame);
+ accessibleFrame->Release();
+ }
+}
+
+// Log messages to the text control
+void MyFrame::Log(const wxString& text)
+{
+ if (m_textCtrl)
+ {
+ wxString text2(text);
+ text2.Replace(wxT("\n"), wxT(" "));
+ text2.Replace(wxT("\r"), wxT(" "));
+ m_textCtrl->SetInsertionPointEnd();
+ m_textCtrl->WriteText(text2 + wxT("\n"));
+ }
+}
+
+// Recursively give information about an object
+void MyFrame::LogObject(int indent, IAccessible* obj)
+{
+ VARIANT var;
+ VariantInit(& var);
+ var.vt = VT_I4;
+ var.lVal = 0;
+
+ BSTR bStrName = 0;
+ HRESULT hResult = obj->get_accName(var, & bStrName);
+
+ if (hResult == S_OK)
+ {
+ wxString strName(wxConvertStringFromOle(bStrName));
+ SysFreeString(bStrName);
+
+ wxString str;
+ str.Printf(wxT("Name: %s"), strName.c_str());
+ str.Pad(indent, wxT(' '), FALSE);
+ Log(str);
+ }
+ else
+ {
+ wxString str;
+ str.Printf(wxT("NO NAME"));
+ str.Pad(indent, wxT(' '), FALSE);
+ Log(str);
+ }
+
+ VARIANT varRole;
+ VariantInit(& varRole);
+
+ hResult = obj->get_accRole(var, & varRole);
+
+ if (hResult == S_OK && varRole.vt == VT_I4)
+ {
+ wxChar buf[256];
+ GetRoleText(varRole.lVal, buf, 256);
+
+ wxString strRole(buf);
+
+ wxString str;
+ str.Printf(wxT("Role: %s"), strRole.c_str());
+ str.Pad(indent, wxT(' '), FALSE);
+ Log(str);
+ }
+ else
+ {
+ wxString str;
+ str.Printf(wxT("NO ROLE"));
+ str.Pad(indent, wxT(' '), FALSE);
+ Log(str);
+ }
+
+ long childCount = 0;
+ if (S_OK == obj->get_accChildCount(& childCount))
+ {
+ wxString str;
+ str.Printf(wxT("There are %d children."), (int) childCount);
+ str.Pad(indent, wxT(' '), FALSE);
+ Log(str);
+ }
+
+ int i;
+ for (i = 1; i <= childCount; i++)
+ {
+ VARIANT var;
+ VariantInit(& var);
+ var.vt = VT_I4;
+ var.lVal = i;
+ IDispatch* pDisp = NULL;
+ IAccessible* childObject = NULL;
+
+ BSTR bStrName = 0;
+ HRESULT hResult = obj->get_accName(var, & bStrName);
+
+ if (hResult == S_OK)
+ {
+ wxString strName(wxConvertStringFromOle(bStrName));
+ SysFreeString(bStrName);
+
+ wxString str;
+ str.Printf(wxT("Name: %s"), strName.c_str());
+ str.Pad(indent+4, wxT(' '), FALSE);
+ Log(str);
+ }
+ else
+ {
+ wxString str;
+ str.Printf(wxT("NO NAME"));
+ str.Pad(indent+4, wxT(' '), FALSE);
+ Log(str);
+ }
+
+ VARIANT varRole;
+ VariantInit(& varRole);
+
+ hResult = obj->get_accRole(var, & varRole);
+
+ if (hResult == S_OK && varRole.vt == VT_I4)
+ {
+ wxChar buf[256];
+ GetRoleText(varRole.lVal, buf, 256);
+
+ wxString strRole(buf);
+
+ wxString str;
+ str.Printf(wxT("Role: %s"), strRole.c_str());
+ str.Pad(indent+4, wxT(' '), FALSE);
+ Log(str);
+ }
+ else
+ {
+ wxString str;
+ str.Printf(wxT("NO ROLE"));
+ str.Pad(indent+4, wxT(' '), FALSE);
+ Log(str);
+ }
+
+ if (S_OK == obj->get_accChild(var, & pDisp) && pDisp)
+ {
+ wxString str;
+ str.Printf(wxT("This is a real object."));
+ str.Pad(indent+4, wxT(' '), FALSE);
+ Log(str);
+
+ if (pDisp->QueryInterface(IID_IAccessible, (LPVOID*) & childObject) == S_OK)
+ {
+ LogObject(indent + 4, childObject);
+ childObject->Release();
+ }
+ pDisp->Release();
+ }
+ else
+ {
+ wxString str;
+ str.Printf(wxT("This is an element."));
+ str.Pad(indent+4, wxT(' '), FALSE);
+ Log(str);
+ }
+ Log(wxT(""));
+ }
+
+}
+