private void ParseClientAreaElement(StringBuilder sb, SystemAccessibleObject sao, int depth) { sb.Append("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); sb.Append(ListContent.Repeat('*', depth) + " " + sao.ToString() + "\n"); try { sb.Append("D: " + sao.Description + "\n"); } catch (COMException) { } try { sb.Append("V: " + sao.Value + "\n"); } catch (COMException) { } foreach (SystemAccessibleObject c in sao.Children) { if (c.Window == sao.Window) ParseClientAreaElement(sb, c, depth + 1); } }
private void LoadTree(SystemAccessibleObject sao) { tree.Nodes.Clear(); if (sao == null) return; IntPtr hwnd = sao.Window.HWnd; List<SystemAccessibleObject> parents = new List<SystemAccessibleObject>(); parents.Add(sao); while (true) { sao = sao.Parent; if (sao == null) break; if (!allParents.Checked && sao.Window.HWnd != hwnd) break; parents.Add(sao); } sao = parents[parents.Count-1]; parents.RemoveAt(parents.Count - 1); TreeNode curr = new TreeNode(sao.ToString()); curr.Tag = sao; tree.Nodes.Add(curr); LoadTreeChildren(curr); while (parents.Count > 0) { sao = parents[parents.Count - 1]; parents.RemoveAt(parents.Count - 1); TreeNode newcurr = null; foreach (TreeNode sub in curr.Nodes) { if ((SystemAccessibleObject)sub.Tag == sao) { newcurr = sub; break; } } if (newcurr == null) { foreach (TreeNode sub in curr.Nodes) { if (sao.Equals((SystemAccessibleObject)sub.Tag)) { newcurr = sub; break; } } } if (newcurr == null) { newcurr = new TreeNode("!! " + sao.ToString()); newcurr.Tag = sao; curr.Nodes.Add(newcurr); } curr = newcurr; LoadTreeChildren(curr); } tree.SelectedNode = curr; }