示例#1
0
        private void Timer1_Tick(object sender, EventArgs e)
        {
            Form1.GetCursorPos(ref this.P);
            this.Pt.X = (double)this.P.x;
            this.Pt.Y = (double)this.P.y;
            try
            {
                this.CurrentElement = AutomationElement.FromPoint(this.Pt);
                AutomationElement.AutomationElementInformation current = this.CurrentElement.Current;
                bool flag = current.ProcessId == Process.GetCurrentProcess().Id;
                if (flag)
                {
                    return;
                }
            }
            catch (Exception expr_7A)
            {
                ProjectData.SetProjectError(expr_7A);
                ProjectData.ClearProjectError();
            }
            this.DrawRectangle();
            bool flag2 = ((int)Form1.GetAsyncKeyState(17) & 32768) != 0;

            if (flag2)
            {
                AutomationElement.AutomationElementInformation current = this.CurrentElement.Current;
                this.RootElement = this.CurrentElement;
                this.TW          = TreeWalker.ControlViewWalker;

                // 上一个节点
                AutomationElement lastElement = this.TW.GetParent(this.RootElement);
                AutomationElement.AutomationElementInformation lastAutomationElementInformation = lastElement.Current;

                while (true)
                {
                    bool flag3 = this.TW.GetParent(this.RootElement).Equals(AutomationElement.RootElement);
                    if (flag3)
                    {
                        break;
                    }
                    this.RootElement = this.TW.GetParent(this.RootElement);
                }

                //  找到上一级

                /*this.TreeView1.Nodes.Clear();
                 * TreeNodeCollection treeNodeCollection = this.TreeView1.Nodes;
                 * current = this.RootElement.Current;
                 * this.RootNode = treeNodeCollection.Add(current.Name + " " + current.LocalizedControlType.ToString());
                 * this.dic = new Dictionary<TreeNode, AutomationElement>();
                 * this.dic.Add(this.RootNode, this.RootElement);
                 * this.LoopElement(this.RootElement, this.RootNode);
                 *//*Console.WriteLine("parent:"+ this.dic(this.RootNode.LastNode));*/


                string pearentName  = this.RootElement.Current.Name;
                string pearentClass = this.RootElement.Current.ClassName;

                /*string[] sourceArray = new string[]
                 * {
                 *      "父名称:" + pearentName,
                 *      "父类名:" + pearentClass,
                 *      "名称:" + current.Name,
                 *      "本地类型:" + current.LocalizedControlType,
                 *      "控件类型:" + current.ControlType.ProgrammaticName,
                 *      "类名:" + current.ClassName,
                 *      "句柄:" + Conversions.ToString(current.NativeWindowHandle),
                 *      "进程:" + Conversions.ToString(current.ProcessId)
                 * };
                 * MessageBox.Show(Strings.Join(sourceArray, "\r\n"), "句柄信息");*/
                Dictionary <string, object> rootParent = new Dictionary <string, object>();
                rootParent.Add("currentName", this.RootElement.Current.Name);
                rootParent.Add("currentClassName", this.RootElement.Current.ClassName);
                rootParent.Add("currentNativeWindowHandle", Conversions.ToString(this.RootElement.Current.NativeWindowHandle));
                rootParent.Add("currentProcessId", Conversions.ToString(this.RootElement.Current.ProcessId));
                rootParent.Add("currentControlTypeProgrammaticName", this.RootElement.Current.ControlType.ProgrammaticName);
                rootParent.Add("AutomationId", this.RootElement.Current.AutomationId);
                rootParent.Add("index", "1");
                Dictionary <string, object> lastParent = new Dictionary <string, object>();
                lastParent.Add("currentName", lastAutomationElementInformation.Name);
                lastParent.Add("currentClassName", lastAutomationElementInformation.ClassName);
                lastParent.Add("currentNativeWindowHandle", Conversions.ToString(lastAutomationElementInformation.NativeWindowHandle));
                lastParent.Add("currentProcessId", Conversions.ToString(lastAutomationElementInformation.ProcessId));
                lastParent.Add("currentControlTypeProgrammaticName", lastAutomationElementInformation.ControlType.ProgrammaticName);
                lastParent.Add("AutomationId", lastAutomationElementInformation.AutomationId);
                Dictionary <string, object> dictionary = new Dictionary <string, object>();
                dictionary.Add("rootParent", rootParent);
                dictionary.Add("lastParent", lastParent);
                dictionary.Add("currentName", current.Name);
                dictionary.Add("text", current.Name);
                dictionary.Add("currentClassName", current.ClassName);
                dictionary.Add("currentNativeWindowHandle", Conversions.ToString(current.NativeWindowHandle));
                dictionary.Add("currentProcessId", Conversions.ToString(current.ProcessId));
                dictionary.Add("currentControlTypeProgrammaticName", current.ControlType.ProgrammaticName);
                dictionary.Add("AutomationId", current.AutomationId);
                dictionary.Add("x", this.Rec.Left);
                dictionary.Add("y", this.Rec.Top);
                dictionary.Add("w", this.Rec.Right);
                dictionary.Add("h", this.Rec.Bottom);
                /*dictionary.Add("AccessKey", current.AccessKey);*/

                // 截图 转字符串
                this.Rec = current.BoundingRectangle;
                Console.WriteLine("this.Rec.Left:" + this.Rec.Left.ToString() + ",this.Rec.Top:" + this.Rec.Top.ToString() + ",this.Rec.Right:" + this.Rec.Right.ToString() + ",this.Rec.Bottom:" + this.Rec.Bottom.ToString());
                Form1.Rectangle(this.hDC, (int)Math.Round(this.Rec.Left), (int)Math.Round(this.Rec.Top), (int)Math.Round(this.Rec.Right), (int)Math.Round(this.Rec.Bottom));
                MouseHookHelper.SetCursorPos(0, 0);
                Thread.Sleep(150);
                String imagePath = this.SaveImage((int)Math.Round(this.Rec.Left), (int)Math.Round(this.Rec.Top), (int)Math.Round(this.Rec.Right - this.Rec.Left), (int)Math.Round(this.Rec.Bottom - this.Rec.Top));
                // string base64FromImage = ImageUtil.GetBase64FromImage(image);
                dictionary.Add("screenShot", imagePath);
                PostData(dictionary);
            }
            else
            {
                this.ShowProperty();
            }
        }
示例#2
0
        public override void Execute()
        {
            switch (ViewType)
            {
            case DAAViewType.Idle:
                View = new DAAWindow(this);
                View.ShowDialog();
                break;

            case DAAViewType.Close:
                View.Close();
                break;

            case DAAViewType.PickSinglePipe_Pipe:
                //业务逻辑处理
                if (!MouseHookHelper.DelegateMouseHook(() =>
                {
                    //业务逻辑处理
                    //选择符合类型的过滤
                    var reference = UIDocument.Selection.PickObject(ObjectType.Element, Model.GetFilter(), "请选择需要标注的对象");
                    if (reference != null)
                    {
                        Model.TargetId = reference.ElementId;
                    }
                }))
                {
                    ViewType = DAAViewType.Idle;
                    Execute();
                    return;
                }
                //族准备
                if (!TransactionHelper.DelegateTransaction(Document, "GetFamilySymbolInfo", (Func <bool>)(() =>
                {
                    var annotationFamily = Model.GetAnnotationFamily(Document);
                    return(annotationFamily != null);
                })))
                {
                    DAAContext.Creator.Generate(Document, Model);
                }
                Execute();
                break;

            //case DAAViewType.PickSinglePipe_Location:
            //    if (!MouseHookHelper.DelegateMouseHook(() =>
            //    {
            //        //业务逻辑处理
            //        var target = Document.GetElement(Model.TargetIds.First());
            //        var targetLocation = target.Location as LocationCurve;
            //        var p0 = targetLocation.Curve.GetEndPoint(0);
            //        var p1 = targetLocation.Curve.GetEndPoint(1);
            //        var pStart = new XYZ((p0.X + p1.X) / 2, (p0.Y + p1.Y) / 2, (p0.Z + p1.Z) / 2);
            //        var pEnd = new VLPointPicker().PickPointWithLinePreview(UIApplication, pStart);
            //        if (pEnd == null)
            //            ViewType = DAAViewType.Idle;
            //        else
            //            ViewType = DAAViewType.GenerateSinglePipe;
            //    }))
            //        ViewType = DAAViewType.Idle;
            //    Execute();
            //    break;
            //case DAAViewType.GenerateSinglePipe:
            //    if (TransactionHelper.DelegateTransaction(Document, "GenerateSinglePipe", (Func<bool>)(() =>
            //        {
            //            var element = Document.GetElement(Model.TargetIds.First());
            //            var Collection = DAAContext.GetCollection(Document);
            //            //避免重复生成 由于一个对象可能在不同的视图中进行标注设置 所以还是需要重复生成的
            //            var existedModels = Collection.Data.Where(c => c.TargetIds.Intersect(Model.TargetIds, new ElementIdComparer()) != null);
            //            if (existedModels != null)
            //            {
            //                foreach (var existedModel in existedModels)
            //                {
            //                    Collection.Data.Remove(existedModel);
            //                    DAAContext.Creator.Clear(Document, existedModel);
            //                }
            //            }
            //            DAAContext.Creator.Generate(Document, Model, element);
            //            Collection.Data.Add(Model);
            //            Collection.Save(Document);
            //            return true;
            //        })))
            //            ViewType = DAAViewType.PickSinglePipe_Pipe;
            //    else
            //        ViewType = DAAViewType.Idle;
            //    Execute();
            //break;
            default:
                throw new NotImplementedException("功能未实现");
            }
        }