|
下面是我使用c#代码,捕获aa的例子。结果一直是捕获不出来,大家可否指点一下,是什么原因。
这个例子是参考别人的写的。用来获取遨游浏览器的标准工具栏里的按钮。
问题
1、 IntPtr hwnd2 = FindWindowEx(hWnd, IntPtr.Zero, "XTPToolBar", "标准工具栏");
这个函数返回了空值。不明白为什么。遨游浏览器里有很多的XTPToolBar,所以我才加入了标题。
2、 我尝试了其他的控件,比如火狐浏览器的控件。
在找到子窗口对应的aa后,调用
AccessibleChildren(accessible, 0, accessible.accChildCount - 1, childs, out obtained);
竟然不能得到他们的子对象。即使父对象里显示有多个子对象。得到的childs是空的数组。
public static void msaa()
{
object obj = new object();
IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "Maxthon2_Frame", null);//get the parent hwnd
IntPtr hwnd2 = FindWindowEx(hWnd, IntPtr.Zero, "XTPToolBar", "标准工具栏"); //get the sub window
Guid guid = new Guid("{618736E0-3C3D-11CF-810C-00AA00389B71}");
AccessibleObjectFromWindow(hwnd2, 0x00000000, ref guid, ref obj);//get the aa object
IAccessible accessible = obj as IAccessible;
accessible = accessible.accParent as IAccessible;//get the parent aa object
Object[] childs = new Object[accessible.accChildCount]; //set a array to receive the sub aa object list
int obtained = 0;
AccessibleChildren(accessible, 0, accessible.accChildCount - 1, childs, out obtained);//get the sub aa objects
Console.WriteLine(obtained.ToString());//print count to verify the result
//print relative information ,not very importent .
for (int i = 0; i < obtained; i++)
{
IAccessible child = childs as IAccessible;
try { Console.WriteLine(child.get_accName(0)); }
catch { }
Object[] accchilds = new Object[child.accChildCount];
int result = 0;
AccessibleChildren(child, 0, child.accChildCount - 1, accchilds, out result);
for (int j = 0; j < result; j++)
{
IAccessible jchild = accchilds[j] as IAccessible;
Console.WriteLine(jchild.get_accName(0));
}
}
Console.ReadLine();
} |
|