public ViewTree(IUIAutomationElement element, IUIAutomation automation) { this.root = new TreeNode(element); this.root.parent = null; IUIAutomationElementArray array = element.FindAll(TreeScope.TreeScope_Children, automation.CreateTrueCondition()); if (0 == array.Length) { this.root.children = null; this.root.isLeaf = true; } else { for (int i = 0; i < array.Length; i++) { IUIAutomationElement e = array.GetElement(i); TreeNode n = new TreeNode(e); this.root.children.Add(n); } } }
public void MyTestInitialize() { // Create the factory and register schemas _nFactory = new CUIAutomationClass(); // Start the app var curDir = Environment.CurrentDirectory; _app = new TargetApp(curDir + "\\WpfAppWithAdvTextControl.exe"); _app.Start(); // Find the main control var appElement = _nFactory.ElementFromHandle(_app.MainWindow); var advTestBoxCondition = _nFactory.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "advTextBox1"); _nAdvancedTextBoxElement = appElement.FindFirst(NTreeScope.TreeScope_Children, advTestBoxCondition); Assert.IsNotNull(_nAdvancedTextBoxElement); var testControlCondition = _nFactory.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "testControl"); _nTestControlElement = appElement.FindFirst(NTreeScope.TreeScope_Children, testControlCondition); Assert.IsNotNull(_nTestControlElement); var window = AutomationElement.RootElement.FindFirst(WTreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "MainWindow")); _wAdvancedTextBoxElement = window.FindFirst(WTreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "advTextBox1")); _wTestControlElement = window.FindFirst(WTreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "testControl")); }
/// <summary> /// Build a cacherequest for properties and patterns /// </summary> /// <param name="uia"></param> /// <param name="pps">Property ids</param> /// <param name="pts">Pattern ids</param> /// <returns></returns> public static IUIAutomationCacheRequest GetPropertiesCache(IUIAutomation uia, List <int> pps, List <int> pts) { if (uia == null) { throw new ArgumentNullException(nameof(uia)); } var cr = uia.CreateCacheRequest(); if (pps != null) { foreach (var pp in pps) { cr.AddProperty(pp); } } if (pts != null) { foreach (var pt in pts) { if (pt != 0) { cr.AddPattern(pt); } } } return(cr); }
public static bool CollapseAll(this IUIAutomationElement element, IUIAutomation automation) { if (element.CurrentIsOffscreen != 0) { return(false); } var returnValue = false; var condition = automation.CreatePropertyCondition(UIA_PropertyIds.UIA_IsEnabledPropertyId, true); var item = element.FindAll(TreeScope.TreeScope_Children, condition); for (var i = 0; i < item.Length; i++) { if (CollapseAll(item.GetElement(i), automation)) { returnValue = true; } } if (!(element.GetCurrentPattern(UIA_PatternIds.UIA_ExpandCollapsePatternId) is IUIAutomationExpandCollapsePattern expandCollapsePattern) || expandCollapsePattern.CurrentExpandCollapseState == ExpandCollapseState.ExpandCollapseState_LeafNode) { return(returnValue); } expandCollapsePattern.Collapse(); return(true); }
private void ThreadProc() { // *** Note: The thread on which the UIA calls are made below must be MTA. automation = new CUIAutomation(); autoEventInit.Set(); bool closeDown = false; while (!closeDown) { // Wait here until we're told we have some work to do. autoEventMsg.WaitOne(); while (true) { EventMsgData msgData; // Note that none of the queue or message related action here is specific to UIA. // Rather it is only a means for the main UI thread and the background MTA thread // to communicate. // Get a message from the queue of action-related messages. Monitor.Enter(msgQueue); try { // An exception is thrown when the queue is empty. msgData = msgQueue.Dequeue(); } catch (InvalidOperationException) { // InvalidOperationException is thrown if the queue is empty. msgData.msgType = EventMsgType.msgNull; msgData.element = null; msgData.useCache = false; break; } finally { // Ensure that the lock is released. Monitor.Exit(msgQueue); } if (msgData.msgType == EventMsgType.msgMessageBulidList) { // We will be here following a press of the Refresh button by the user. BuildListOfMsgFromWindowInternal(false, false); } else if (msgData.msgType == EventMsgType.msgCloseDown) { //메인쓰레드 에서 메세지 후킹 쓰레드 종료 Msg 처리. closeDown = true; break; } } } }
public Window(IntPtr handle, IUIAutomation uiAutomation, IKeyboard keyboard, IWinUserWrap winUserWrap) { this.Handle = handle; this.uiAutomation = uiAutomation; this.keyboard = keyboard; this.winUserWrap = winUserWrap; }
public void MyTestInitialize() { // Create the factory and register schemas _nFactory = new CUIAutomationClass(); // Start the app var curDir = Environment.CurrentDirectory; _app = new TargetApp(curDir + "\\WpfAppWithAdvTextControl.exe"); _app.Start(); // Find the main control var appElement = _nFactory.ElementFromHandle(_app.MainWindow); var advTestBoxCondition = _nFactory.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "advTextBox1"); _nAdvancedTextBoxElement = appElement.FindFirst(NTreeScope.TreeScope_Children, advTestBoxCondition); Assert.IsNotNull(_nAdvancedTextBoxElement); var testControlCondition = _nFactory.CreatePropertyCondition(UIA_PropertyIds.UIA_AutomationIdPropertyId, "testControl"); _nTestControlElement = appElement.FindFirst(NTreeScope.TreeScope_Children, testControlCondition); Assert.IsNotNull(_nTestControlElement); var window = AutomationElement.RootElement.FindFirst(WTreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "MainWindow")); _wAdvancedTextBoxElement = window.FindFirst(WTreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "advTextBox1")); _wTestControlElement = window.FindFirst(WTreeScope.Descendants, new PropertyCondition(AutomationElement.AutomationIdProperty, "testControl")); }
public Window(IntPtr handle, IUIAutomation uiAutomation, IKeyboard keyboard, IWinUserWrap winUserWrap) { this.Handle = handle; this.uiAutomation = uiAutomation; this.keyboard = keyboard; this.winUserWrap = winUserWrap; }
public void Uninitialize() { if (_automation != null) { _automation = null; } }
static AutomationManager() { BandObjectLib.Logging.Add_DEBUG("Constructor.log", "AutomationManager"); Guid rclsid = CLSID_CUIAutomation; Guid riid = IID_IUIAutomation; object obj; PInvoke.CoCreateInstance(ref rclsid, IntPtr.Zero, 1, ref riid, out obj); pAutomation = obj as IUIAutomation; Thread automationThread = new Thread(Dispatcher.Run) { IsBackground = true }; automationThread.Start(); while (true) { automationDispatch = Dispatcher.FromThread(automationThread); if (automationDispatch != null) { break; } Thread.Sleep(50); } }
public static bool ExpandAll(this IUIAutomationElement element, IUIAutomation automation, int level) { if (element.CurrentIsOffscreen != 0) { return(false); } var returnValue = false; if (element.GetCurrentPattern(UIA_PatternIds.UIA_ExpandCollapsePatternId) is IUIAutomationExpandCollapsePattern expandCollapsePattern && expandCollapsePattern.CurrentExpandCollapseState != ExpandCollapseState.ExpandCollapseState_LeafNode) { returnValue = true; // TODO: find timing issue and resolve structurally. This issue shows with CalcVolume Thread.Sleep(100); expandCollapsePattern.Expand(); } var condition = automation.CreatePropertyCondition(UIA_PropertyIds.UIA_IsEnabledPropertyId, true); var item = element.FindAll(TreeScope.TreeScope_Children, condition); for (var i = 0; i < item.Length; i++) { if (ExpandAll(item.GetElement(i), automation, level + 1)) { returnValue = true; } } return(returnValue); }
static void Uninitialize() { if (pAutomation != null) { Marshal.ReleaseComObject(pAutomation); pAutomation = null; } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (_automation != null) { _automation = null; } timer1.Stop(); }
public FindElementHandler( IUIAutomation uiAutomation, IOverlay overlay, IElementFactory elementFactory, IElementSearcher searcher) { this.uiAutomation = uiAutomation; this.overlay = overlay; this.elementFactory = elementFactory; this.searcher = searcher; }
public void Dispose() { if (pAutomation != null) { Marshal.ReleaseComObject(pAutomation); pAutomation = null; } GC.SuppressFinalize(this); }
private bool allowed; // true = Yes, false = No public UACPromptHandler(IUIAutomation uiAutomation, IKeyboard keyboard) { this.uiAutomation = uiAutomation; this.keyboard = keyboard; this.threadLazy = null; this.stopped = false; this.alive = false; this.allowed = false; }
public FindElementHandler( IUIAutomation uiAutomation, IOverlay overlay, IElementFactory elementFactory, IElementSearcher searcher) { this.uiAutomation = uiAutomation; this.overlay = overlay; this.elementFactory = elementFactory; this.searcher = searcher; }
public override void Init() { IUIAutomation uia = this.IUIAutomation; if (uia != null) { uia.AddAutomationEventHandler(this.EventId, this.Element, this.Scope, null, this); this.IsHooked = true; } }
public UACPromptHandler(IUIAutomation uiAutomation, IKeyboard keyboard) { this.uiAutomation = uiAutomation; this.keyboard = keyboard; this.threadLazy = null; this.stopped = false; this.alive = false; this.allowed = false; }
public AutomationManager() { Guid rclsid = CLSID_CUIAutomation; Guid riid = IID_IUIAutomation; object obj; PInvoke.CoCreateInstance(ref rclsid, IntPtr.Zero, 1, ref riid, out obj); pAutomation = obj as IUIAutomation; automationThread.Start(this); }
public override void Init() { IUIAutomation uia = this.IUIAutomation; if (uia != null) { uia.AddPropertyChangedEventHandler(this.Element, this.Scope, null, this, this.propertyArray); this.IsHooked = true; } }
public ClickDetector(ClickStatus status, CursorCapture capture, CustomizationParameters parameters, MainForm form) { this.status = status; this.capture = capture; this.parameters = parameters; this.form = form; this.lastClick = new cursorInTime(-50, -50, null); InitTimer(); this.automator = new CUIAutomation(); }
public ClickDetector(ClickStatus status, CursorCapture capture, CustomizationParameters parameters, MainForm form) { this.status = status; this.capture = capture; this.parameters = parameters; this.form = form; this.lastClick = new cursorInTime(-50, -50, null); InitTimer(); this.automator = new CUIAutomation(); this.lastSentToBack = 0; }
public FocusChangedEventListener(IUIAutomation uia, HandleUIAutomationEventMessage peDelegate) { if (uia == null) { throw new ArgumentNullException(nameof(uia)); } this.UIAutomation = uia; this.ListenEventMessage = peDelegate; this.UIAutomation.AddFocusChangedEventHandler(null, this); IsHooked = true; }
public override IUIAutomationElement GetUIAutomationElement(IUIAutomation automation) { var listElement = _listElement.GetUIAutomationElement(automation); var listItems = listElement.FindAll( interop.UIAutomationCore.TreeScope.TreeScope_Descendants, automation.CreatePropertyCondition( UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListItemControlTypeId)); return listItems.GetElement(_index); }
public override IUIAutomationElement GetUIAutomationElement(IUIAutomation automation) { var listElement = _listElement.GetUIAutomationElement(automation); var listItems = listElement.FindAll( interop.UIAutomationCore.TreeScope.TreeScope_Descendants, automation.CreatePropertyCondition( UIA_PropertyIds.UIA_ControlTypePropertyId, UIA_ControlTypeIds.UIA_ListItemControlTypeId)); return(listItems.GetElement(_index)); }
public AutomationManager() { Guid rclsid = CLSID_CUIAutomation; Guid riid = IID_IUIAutomation; object obj = null; PInvoke.CoCreateInstance(ref rclsid, IntPtr.Zero, 1, ref riid, out obj); if (obj == null) { return; } pAutomation = obj as IUIAutomation; }
static AutomationElement() { Guid rclsid = CLSID_CUIAutomation; Guid riid = IID_IUIAutomation; object obj = null; PInvoke.CoCreateInstance(ref rclsid, IntPtr.Zero, 1, ref riid, out obj); if (obj == null) { return; } pAutomation = obj as IUIAutomation; rclsid = CLSID_CUIAutomationRegistrar; riid = IID_IUIAutomationRegistrar; PInvoke.CoCreateInstance(ref rclsid, IntPtr.Zero, 1, ref riid, out obj); IUIAutomationRegistrar pRegistrar = obj as IUIAutomationRegistrar; try { UIAutomationPropertyInfo propinfo; propinfo = new UIAutomationPropertyInfo { guid = ItemCount_Property_GUID, pProgrammaticName = "ItemCount", type = UIAutomationType_Int }; pRegistrar.RegisterProperty(propinfo, out UIA_ItemCountPropertyId); propinfo = new UIAutomationPropertyInfo { guid = SelectedItemCount_Property_GUID, pProgrammaticName = "SelectedItemCount", type = UIAutomationType_Int }; pRegistrar.RegisterProperty(propinfo, out UIA_SelectedCountPropertyId); propinfo = new UIAutomationPropertyInfo { guid = ItemIndex_Property_GUID, pProgrammaticName = "ItemIndex", type = UIAutomationType_Int }; pRegistrar.RegisterProperty(propinfo, out UIA_ItemIndexPropertyId); } finally { if (pRegistrar != null) { Marshal.ReleaseComObject(pRegistrar); } } }
public AutomationManager() { Guid rclsid = CLSID_CUIAutomation; Guid riid = IID_IUIAutomation; object obj; PInvoke.CoCreateInstance(ref rclsid, IntPtr.Zero, 1, ref riid, out obj); if (obj == null) { return; } pAutomation = obj as IUIAutomation; lock (automationThread) { automationThread.Start(this); Monitor.Wait(automationThread); } }
protected override void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { if (this.IsHooked) { IUIAutomation uia = this.IUIAutomation; if (uia != null) { uia.RemovePropertyChangedEventHandler(this.Element, this); } } } } base.Dispose(disposing); }
private bool disposedValue; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (IsHooked && this.UIAutomation != null) { try { this.UIAutomation.RemoveFocusChangedEventHandler(this); this.UIAutomation = null; } catch (ThreadAbortException) { // silently ignore exception since a ThreadAbortException is thrown at the process exit. } } disposedValue = true; } }
public void Dispose() { if (automationThread.ThreadState != ThreadState.Stopped) { lock (automationThread) { killingThread = true; while (!threadDying) { Monitor.PulseAll(automationThread); Monitor.Wait(automationThread); } } } if (pAutomation != null) { Marshal.ReleaseComObject(pAutomation); pAutomation = null; } GC.SuppressFinalize(this); }
public ViewTree(IUIAutomationElement element, IUIAutomation automation) { this.root = new TreeNode(element); this.root.parent = null; IUIAutomationElementArray array = element.FindAll(TreeScope.TreeScope_Children, automation.CreateTrueCondition()); if (0 == array.Length) { this.root.children = null; this.root.isLeaf = true; } else { for (int i = 0; i < array.Length; i++) { IUIAutomationElement e = array.GetElement(i); TreeNode n = new TreeNode(e); this.root.children.Add(n); } } }
public void MyTestInitialize() { // Create the factory and register schemas _factory = new CUIAutomationClass(); ReadyStateSchema.GetInstance().Register(); TestSchema.GetInstance().Register(); ColorSchema.GetInstance().Register(); // Start the app var curDir = Environment.CurrentDirectory; _app = new TargetApp(curDir + "\\UiaControls.exe"); _app.Start(); // Find the main control var appElement = _factory.ElementFromHandle(_app.MainWindow); var condition = _factory.CreatePropertyCondition( UIA_PropertyIds.UIA_AutomationIdPropertyId, "triColorControl1"); _customElement = appElement.FindFirst(TreeScope.TreeScope_Children, condition); Assert.IsNotNull(_customElement); }
static AutomationElement() { Guid rclsid = CLSID_CUIAutomation; Guid riid = IID_IUIAutomation; object obj = null; PInvoke.CoCreateInstance(ref rclsid, IntPtr.Zero, 1, ref riid, out obj); if(obj == null) return; pAutomation = obj as IUIAutomation; rclsid = CLSID_CUIAutomationRegistrar; riid = IID_IUIAutomationRegistrar; PInvoke.CoCreateInstance(ref rclsid, IntPtr.Zero, 1, ref riid, out obj); IUIAutomationRegistrar pRegistrar = obj as IUIAutomationRegistrar; try { UIAutomationPropertyInfo propinfo; propinfo = new UIAutomationPropertyInfo { guid = ItemCount_Property_GUID, pProgrammaticName = "ItemCount", type = UIAutomationType_Int }; pRegistrar.RegisterProperty(propinfo, out UIA_ItemCountPropertyId); propinfo = new UIAutomationPropertyInfo { guid = SelectedItemCount_Property_GUID, pProgrammaticName = "SelectedItemCount", type = UIAutomationType_Int }; pRegistrar.RegisterProperty(propinfo, out UIA_SelectedCountPropertyId); propinfo = new UIAutomationPropertyInfo { guid = ItemIndex_Property_GUID, pProgrammaticName = "ItemIndex", type = UIAutomationType_Int }; pRegistrar.RegisterProperty(propinfo, out UIA_ItemIndexPropertyId); } finally { if(pRegistrar != null) Marshal.ReleaseComObject(pRegistrar); } }
/// <summary> /// Build a cacherequest for properties and patterns /// </summary> /// <param name="uia"></param> /// <param name="pps">Property ids</param> /// <param name="pts">Pattern ids</param> /// <returns></returns> public static IUIAutomationCacheRequest GetPropertiesCache(IUIAutomation uia, IEnumerable <int> pps, IEnumerable <int> pts) { if (uia == null) { throw new ArgumentNullException(nameof(uia)); } var cr = uia.CreateCacheRequest(); if (pps != null) { foreach (var pp in pps) { cr.AddProperty(pp); } } IEnumerable <int> cps = Registrar.GetDefaultInstance().GetCustomPropertyRegistrations().Keys; foreach (var cp in cps) { cr.AddProperty(cp); } if (pts != null) { foreach (var pt in pts) { if (pt != 0) { cr.AddPattern(pt); } } } return(cr); }
public void MyTestInitialize() { // Create the factory and register schemas _factory = new CUIAutomationClass(); ReadyStateSchema.GetInstance().Register(); TestSchema.GetInstance().Register(); ColorSchema.GetInstance().Register(); // Start the app var curDir = Environment.CurrentDirectory; _app = new TargetApp(curDir + "\\UiaControls.exe"); _app.Start(); // Find the main control var appElement = _factory.ElementFromHandle(_app.MainWindow); var condition = _factory.CreatePropertyCondition( UIA_PropertyIds.UIA_AutomationIdPropertyId, "triColorControl1"); _customElement = appElement.FindFirst(TreeScope.TreeScope_Children, condition); Assert.IsNotNull(_customElement); }
public WindowFactory(IUIAutomation uiAutomation, IKeyboard keyboard, IWinUserWrap winUserWrap) { this.uiAutomation = uiAutomation; this.keyboard = keyboard; this.winUserWrap = winUserWrap; }
public Element(AutomationElement element, IUIAutomation uiAutomation) { this.element = element; this.uiAutomation = uiAutomation; }
public UIAutomationService(IElementRepository elementRepository) { _automation = new CUIAutomation(); _elementRepository = elementRepository; }
public ActiveElementHandler(IUIAutomation uiAutomation, IOverlay overlay) { this.uiAutomation = uiAutomation; this.overlay = overlay; }
public UIOperator() { this._automation = new CUIAutomation(); }
public WindowUtils(IUIAutomation uiAutomation, IWindowFactory windowFactory) { this.uiAutomation = uiAutomation; this.windowFactory = windowFactory; }
internal AutomationElementFactory(IUIAutomation pAutomation) { disposeList = new List<AutomationElement>(); this.pAutomation = pAutomation; }
public GetTitleHandler(IUIAutomation uiAutomation) { this.uiAutomation = uiAutomation; }
public void SetUIAutomation(IUIAutomation uiAutomation) { this.uiAutomation = uiAutomation; }
public FindElementsHandler(IUIAutomation uiAutomation) { this.uiAutomation = uiAutomation; }
public UIAutomationService(IElementRepository elementRepository) { _automation = new CUIAutomation(); _elementRepository = elementRepository; }
public GetSourceHandler(IUIAutomation uiAutomation) { this.uiAutomation = uiAutomation; }
public SelectionPattern(IUIAutomation automation, IUIAutomationElement element) { _element = element; _automation = automation; _selectionPattern = element.GetCurrentPattern(UIA_PatternIds.UIA_SelectionPatternId) as IUIAutomationSelectionPattern; }
public ElementSearcher(IUIAutomation uiAutomation, IElementFactory elementFactory) { this.uiAutomation = uiAutomation; this.elementFactory = elementFactory; }
public virtual IUIAutomationElement GetUIAutomationElement(IUIAutomation automation) { return automation.ElementFromHandle(new IntPtr(_handle)); }
static void Uninitialize() { if(pAutomation != null) { Marshal.ReleaseComObject(pAutomation); pAutomation = null; } }