示例#1
0
        // 20131114
        //this.getElementFromPoint();
        // 20131210
        // this.getElementFromPoint(Cursor.Position);

        //                        // use Windows forms mouse code instead of WPF
        //                        System.Drawing.Point mouse = System.Windows.Forms.Cursor.Position;
//
        //                        // commented 20120618 to switch to UiaCOMWrapper
        //                        element =
        //                            System.Windows.Automation.AutomationElement.FromPoint(
        //                                new System.Windows.Point(mouse.X, mouse.Y));
        //                        //element =
        //                        //    //(UiaNET::System.Windows.Automation.AutomationElement)
        //                        //    UiaCOM3.UiaCOMHelper.GetAutomationElementFromPoint();

        // 20120618 UiaCOMWrapper
        // && (int)element.Current.ProcessId > 0)
        // if (element != null && ((element as AutomationElement) != null)) { // && (int)element.Current.ProcessId > 0)
        //if (element != null && ((element as UiaCOM::System.Windows.Automation.AutomationElement) != null)) { // && (int)element.Current.ProcessId > 0)
        // 20131210
        // this.createTranscriptingCmdlet();

        // as UiaNET::System.Windows.Automation.AutomationElement);
        //


        //                                this.richTextBox1.Text +=
        //                                    "failed to get element.Current.ProcessId\r\n";
        //                                    this.richTextBox1.Text +=
        //                                        "failed to get  element.Cached.ProcessId\r\n";

        // ||

        // there is usually nothing to report

        // writing to the property grid control

        // writing to the family tree and the code

        //try {
        //}
        //catch (Exception eCollectAncestry) {
        //    this.richTextBox1.Text = eCollectAncestry.Message;
        //}

        // the Hierarchy tree

        // the code generated

        //
        // 20131114
        //

        // 20131210
        // writingAvailablePatterns(element);

        // end of if (elementPID != tabooPID)
        // end of if (element != null && ((element as AutomationElement) != null))
        // +


        public void ProcessSpyingCycle() //TranscriptCmdletBase cmdlet, IUiElement element)
        {
            do
            {
                Application.DoEvents();

                try {
                    // use Windows forms mouse code instead of WPF
                    IUiElement element = ExSpyCode.GetElementFromPoint(Cursor.Position);

                    if (null != element)
                    {
                        TranscriptCmdletBase cmdlet = ExSpyCode.CreateTranscriptingCmdlet();
                        try {
                            bool res = UiaHelper.ProcessingElement(cmdlet, element);
                            if (!res)
                            {
                            }
                        } catch (Exception eProcessingElement) {
                            txtFullCode.Text = "eProcessingElement element method:\r\n" + eProcessingElement.Message;
                            element          = null;
                            System.Threading.Thread.Sleep(Preferences.TranscriptInterval);
                            continue;
                        }

                        int elementPID = 0;
                        try {
                            // 20140312
                            // elementPID = element.Current.ProcessId;
                            elementPID = element.GetCurrent().ProcessId;
                        } catch {
                            try {
                                // 20140312
                                // elementPID = element.Cached.ProcessId;
                                // elementPID = (element as ISupportsCached).Cached.ProcessId;
                                elementPID = element.GetCached().ProcessId;
                            } catch (Exception) {
                            }
                        }

                        // 20131227
                        // int elementPID = UiaHelper.GetElementProcessIdSafely(element);
                        if (elementPID != tabooPID)
                        {
                            if (cmdlet.LastRecordedItem.Count > 0)
                            {
                                try {
                                    richControlCode.Text = cmdlet.WritingRecord(cmdlet.LastRecordedItem, null, null, null);
                                    if (chkClipboard.Checked)
                                    {
                                        Clipboard.SetDataObject(richControlCode.Text);
                                    }
                                } catch (Exception eCollectingElements) {
                                    txtFullCode.Text = "Collecting:\r\n" + eCollectingElements.Message;
                                    Exception eCollectingElements2 = new Exception("Collecting (eCollectingElements):\r\n" + eCollectingElements.Message);
                                    throw (eCollectingElements2);
                                }
                                guiWritingAutomationElementToPropertyGridControl(element);
                                try {
                                    collectAncestry(ref ancestorsNodesList, ref ancestorsCodeList, element);
                                    guiFillHierarchyTree();
                                    guiWriteCodeGenerated();
                                } catch (Exception eInner) {
                                    txtFullCode.Text += "Inner cycle (eInner):\r\n" + eInner.Message;
                                }
                            }
                            richPatterns.Text = ExSpyCode.WritingAvailablePatterns(element);
                        }
                    }

                    System.Threading.Thread.Sleep(Preferences.TranscriptInterval);
                } catch (Exception eUnknown) {
                    txtFullCode.Text += "External cycle (eUnknown):\r\n" + eUnknown.Message;
                    System.Threading.Thread.Sleep(Preferences.TranscriptInterval);
                }
            } while (!stopNow);
        }