예제 #1
0
        // 작업 결과 값을 반환할 경우 CodeActivity<TResult>에서 파생되고
        // Execute 메서드에서 값을 반환합니다.
        protected override void Execute(CodeActivityContext context)
        {
            // 텍스트 입력 인수의 런타임 값을 가져옵니다.
            string text = context.GetValue(this.Text);

            HWND hWnd = context.GetValue(this.WindowHandle);

            if (hWnd == IntPtr.Zero)
            {
                int nRetryCnt = 0;
                while (nRetryCnt < m_RetrySec)
                {
                    Debug.WriteLine("FindWindow {0}, {1}", ProcessName, WindowTitle);

                    hWnd = WindowList.FindWindowByTitle(ProcessName, WindowTitle, false);   //"notepad++", "Notepad"
                    if (hWnd != IntPtr.Zero)
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                    nRetryCnt++;
                }

                if (hWnd == IntPtr.Zero)
                {
                    Debug.WriteLine("Not Found Window");
                    return;
                }
            }

            Debug.WriteLine("Maxmize Window");

            WindowList.ShowMaxmizeWindow(hWnd);
        }
예제 #2
0
        // 작업 결과 값을 반환할 경우 CodeActivity<TResult>에서 파생되고
        // Execute 메서드에서 값을 반환합니다.
        protected override void Execute(CodeActivityContext context)
        {
            // 텍스트 입력 인수의 런타임 값을 가져옵니다.
            string text = context.GetValue(this.Text);

            this.ResultBool.Set(context, false);

            HWND hWnd = context.GetValue(this.WindowHandle);

            if (hWnd == IntPtr.Zero)
            {
                int nRetryCnt = 0;
                while (nRetryCnt < m_RetrySec)
                {
                    Debug.WriteLine("FindWindow {0}, {1}", ProcessName, WindowTitle);

                    hWnd = WindowList.FindWindowByTitle(ProcessName, WindowTitle, false);   //"notepad++", "Notepad"
                    if (hWnd != IntPtr.Zero)
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                    nRetryCnt++;
                }

                if (hWnd == IntPtr.Zero)
                {
                    Debug.WriteLine("Not Found Window");
                    return;
                }
            }

            m_FoundWindowHandle = hWnd;

            Debug.WriteLine("Found Window");

            ControlType       controlType;
            AutomationElement foundElement = null;

            if (hWnd != IntPtr.Zero)
            {
                System.Windows.Automation.ControlType.Button.ToString();  // ControlType class bug ㅜ.ㅜ, 첫번째 호출시 결과 return 안됨. tostring 호출하여 먼저 초기화 필요

                int nRetryCnt = 0;
                while (nRetryCnt < m_RetrySec)
                {
                    controlType = System.Windows.Automation.ControlType.LookupById(int.Parse(m_ControlTypeId));

                    Debug.WriteLine("controlTypeId :  {0}, {1}", m_ControlTypeId, controlType);
                    Debug.WriteLine("Find element {0}, {1}", ControlName, controlType.ToString());

                    foundElement = FindElement(hWnd, AutomationId, ControlName, controlType);

                    if (foundElement != null)
                    {
                        break;
                    }

                    Thread.Sleep(1000);
                    nRetryCnt++;
                }
            }

            if (foundElement == null)
            {
                Debug.WriteLine("Not Found Element");
                return;
            }

            Debug.WriteLine("Found Element");

            /*
             *          try
             *          {
             *              foundElement.SetFocus();
             *          }
             *          catch(Exception ex)
             *          {
             *              PrintExceptionLog(ex);
             *          }
             */

            int x = 0, y = 0;

            try
            {
                var clickablePoint = foundElement.GetClickablePoint();

                x = (int)clickablePoint.X;
                y = (int)clickablePoint.Y;
            }
            catch (Exception ex)
            {
                System.Windows.Rect rect = foundElement.Current.BoundingRectangle;

                if (rect.X > 0 && rect.Y > 0)
                {
                    x = (int)(rect.X + rect.Width) / 2;    //center
                    y = (int)(rect.Y + rect.Height) / 2;   //center
                }
            }


            Debug.WriteLine("Point {0}, {1}", x, y);
            if (x > 0 && y > 0)
            {
                Cursor.Position = new System.Drawing.Point(x, y);
                //Cursor.Clip = new Rectangle(this.Location, this.Size);
            }


            if ((x <= 0 || y <= 0) && MouseClickAction != MouseClickType.None)
            {
                object objPattern;
                if (true == foundElement.TryGetCurrentPattern(InvokePattern.Pattern, out objPattern))
                {
                    InvokeControl(foundElement);
                }
            }
            else
            {
                if (MouseClickAction == MouseClickType.Click)
                {
                    DoMouseClickEvent(MouseButton, x, y);
                }

                if (MouseClickAction == MouseClickType.DblClick)
                {
                    DoMouseDblClickEvent(MouseButton, x, y);
                }
            }

            WaitForCompleted();


            this.ResultBool.Set(context, true);
        }