[S/W 접근성] TreeWalker 개체 참조
4.1 TreeWalker 개체 참조
TreeWalker 개체를 참조하는 방법에는 TreeWalker의 정적 필드를 통해 미리 제공하고 있는 TreeWalker 개체를 참조하는 방법과 원하는 조건을 인자로 새로운 TreeWalker 개체를 생성하는 방법이 있습니다.
public static readonly TreeWalker RawViewWalker;
public static readonly TreeWalker ControlViewWalker;
public static readonly TreeWalker ContentViewWalker;
publid TreeWalker(Condition condition);
이번에는 원하는 조건을 인자로 새로운 트리 개체를 생성하는 예를 살펴볼게요. 여기에서는 윈도우즈 패턴과 사용 가능한 패턴을 동시에 만족하는 조건으로 데스크 톱의 자식 요소에서 탐색할게요. (메인 창이나 팝업 창이 검색되겠죠.)
Condition cond1 = new PropertyCondition(
AutomationElement.IsWindowPatternAvailableProperty, true);
Condition cond2 = new PropertyCondition(
AutomationElement.IsEnabledProperty, true);
Condition condition = new AndCondition(cond1, cond2);
TreeWalker tw = new TreeWalker(condition);
using System; using System.Windows.Automation; using System.Runtime.InteropServices;
namespace 자동화_트리_개체_생성 { static class WrapApi { [DllImport("user32")] internal static extern IntPtr GetDesktopWindow(); }
class Program { static void Main(string[] args) { AutomationElement ae = AutomationElement.FromHandle( WrapApi.GetDesktopWindow()); ListAE(ae, 0); } private static void ListAE(AutomationElement ae, int depth) { Condition cond1 = new PropertyCondition( AutomationElement.IsWindowPatternAvailableProperty, true); Condition cond2 = new PropertyCondition( AutomationElement.IsEnabledProperty, true); TreeWalker tw = new TreeWalker(new AndCondition(cond1, cond2)); if (ae == null) { return; } ViewAE(ae, depth); AutomationElement cae = tw.GetFirstChild(ae); while (cae != null) { ListAE(cae, depth + 1); cae = tw.GetNextSibling(cae); } } private static void ViewAE(AutomationElement ae, int depth) { Console.WriteLine("{0}:{1}", ae.Current.Name, depth); } } } |
[소스 4.2] 자동화 트리 개체 생성