public void spy() { var curtime = DateTime.Now; try { log.Info("BEGIN SPY FROM HIGHLIGHT FORM"); Process targetProcess = WindowInteraction.GetProcess(ProcessName); //WindowInteraction.FocusWindow(targetProcess); App = Gu.Wpf.UiAutomation.Application.Attach(targetProcess.Id); MainWindow = App.MainWindow; ElementList = GrabAUT.SearchbyFramework("WPF"); dataGridView1.Rows.Clear(); dataGridView1.AllowUserToAddRows = true; SpyObjectList = new SpyObject[ElementList.Count]; int SpyObjectIndex = 0; //comboBox1.Enabled = false; for (int i = 0; i < ElementList.Count; i++) { SpyObjectList[SpyObjectIndex] = new SpyObject(); SpyObjectList[SpyObjectIndex].index = SpyObjectIndex; if (ElementList[i].AutomationId == "" && SpyObjectIndex - 1 > 0 && ElementList[i - 1].Name != "" && ElementList[i].Name == "") { SpyObjectList[SpyObjectIndex].automationId = (ElementList[i - 1].Name + "_" + ElementList[i].ClassName).Replace(" ", "_").Replace(":", ""); } else { SpyObjectList[SpyObjectIndex].automationId = ElementList[i].AutomationId; } SpyObjectList[SpyObjectIndex].name = ElementList[i].Name; SpyObjectList[SpyObjectIndex].type = ElementList[i].ClassName; DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[i].Clone(); row.Cells[0].Value = SpyObjectList[SpyObjectIndex].index; row.Cells[1].Value = SpyObjectList[SpyObjectIndex].automationId; row.Cells[2].Value = SpyObjectList[SpyObjectIndex].name; row.Cells[3].Value = SpyObjectList[SpyObjectIndex].type; dataGridView1.Rows.Add(row); SpyObjectIndex++; } log.Info("SPY DONE OF HIGHLIGHT"); dataGridView1.AllowUserToAddRows = false; comboBox1.SelectedIndex = 0; } catch (Exception ex) { log.Error("ERROR CODE: " + ex.HResult + " ----- " + "detail: " + ex.Message); } }
public void highlight(int objectID) { var curtime = DateTime.Now; try { log.Info("BEGIN HIGHLIGHT"); Process targetProcess = WindowInteraction.GetProcess(ProcessName); GrabAUT.GetMainWindow(); ElementList = GrabAUT.SearchbyFramework("WPF"); SpyObjectList = new SpyObject[ElementList.Count]; int SpyObjectIndex = 0; for (int i = 0; i < ElementList.Count; i++) { SpyObjectList[SpyObjectIndex] = new SpyObject(); SpyObjectList[SpyObjectIndex].index = SpyObjectIndex; if (ElementList[i].AutomationId == "" && SpyObjectIndex - 1 > 0 && ElementList[i - 1].Name != "" && ElementList[i].Name == "") { SpyObjectList[SpyObjectIndex].automationId = (ElementList[i - 1].Name + "_" + ElementList[i].ClassName).Replace(" ", "_").Replace(":", ""); } else { SpyObjectList[SpyObjectIndex].automationId = ElementList[i].AutomationId; } SpyObjectList[SpyObjectIndex].name = ElementList[i].Name; SpyObjectList[SpyObjectIndex].type = ElementList[i].ClassName; if (SpyObjectList[SpyObjectIndex].index == objectID) { for (int a = 0; a < 3; a++) { ElementList[SpyObjectList[SpyObjectIndex].index].DrawHighlight(true, Color.Red, TimeSpan.FromSeconds(1)); } } SpyObjectIndex++; } log.Info("DONE HIGHLIGHT"); } catch (Exception ex) { log.Error("ERROR CODE: " + ex.HResult + " ----- " + "detail: " + ex.Message); } }