예제 #1
0
 public SUIWindow(SUIWindow win)
 {
     if (win == null || win.WindowHandle == null || win.WindowHandle.Equals(IntPtr.Zero))
     {
         throw new SUINullWindowException();//Exception(SUIBaseErrorMessages.Window_CannotInitializeWindow);
     }
     this.hwnd = win.WindowHandle;
 }
예제 #2
0
 //If needMax != 0, we will maxmize the main window.
 public virtual void BringToForeground(int needMax)
 {
     if (Process != null && MainWindow != null)
     {
         SUIWindow.SetForegroundWindow(MainWindow);
         if (needMax != 0)
         {
             MainWindow.Maximized = true;
         }
         SUIWindow.MinimizeAllWindow(MainWindow);
     }
 }
예제 #3
0
        public static SUIWindow GetForegroundWindow()
        {
            SUIWindow sui = null;
            IntPtr    ptr = SUIWinAPIs.GetForegroundWindow();

            if (ptr.Equals(IntPtr.Zero))
            {
                return(null);
            }
            sui = new SUIWindow(ptr);
            return(sui);
        }
예제 #4
0
        // find window Note: took out sibling, may need to add a function for this.
        public static SUIWindow FindSMARTUIWindow(SUIWindow parent, string classname, string windowtext)
        {
            SUIWindow sui = null;
            IntPtr    ptr = SUIWinAPIs.FindWindowEx(parent.hwnd, IntPtr.Zero, classname, windowtext);

            if (!ptr.Equals(IntPtr.Zero))
            {
                sui = new SUIWindow(ptr);
                //With below statement, we could avoid the invisible windows.
                if (!SUIWinAPIs.IsWindowVisible(ptr))
                {
                    sui = FindSMARTUIWindow(parent, sui, classname, windowtext);
                }
            }
            return(sui);
        }
예제 #5
0
        public bool IsCenterOfBackground(SUIWindow backGroundWin)
        {
            int backGroundLeft   = backGroundWin.X;
            int backGroundTop    = backGroundWin.Y;
            int backGroundRight  = backGroundWin.Width;
            int backGroundBottom = backGroundWin.Height;

            if (
                Math.Abs(((backGroundLeft + backGroundRight) / 2 - (this.X + this.Width) / 2)) < 10 &&
                Math.Abs(((backGroundTop + backGroundBottom) / 2 - (this.Y + this.Height) / 2)) < 10
                )
            {
                return(true);
            }
            return(false);
        }
예제 #6
0
        public SUIWindow GetClientWindow()
        {
            IEWin.BringToTopMost();
            SUIWindow client = null;

            if (SUIIE.Version == 6)
            {
                client = IEWin.FindChildWindow("Shell DocObject View", string.Empty);
            }
            else
            {
                SUIWindow temp = IEWin.FindChildWindow("TabWindowClass", IEWin.WindowText);
                client = temp.FindChildWindow("Shell DocObject View", string.Empty);
            }
            return(client);
        }
예제 #7
0
        public static void MinimizeAllWindow(SUIWindow exception)
        {
            SUIWindowCollection windows = SUIWindow.DesktopWindow.Items;

            foreach (SUIWindow win in windows)
            {
                if (exception != null)
                {
                    // If current window is the exception window or child window of the exception window.
                    SUIWindow parent = win.Parent;
                    if (win.WindowHandle.Equals(exception.WindowHandle) || (parent != null && parent.WindowHandle.Equals(exception.WindowHandle)))
                    {
                        continue;
                    }
                }
                win.Minimized = true;
            }
        }
예제 #8
0
        public static SUIIE CreateIEWithURL(string URL)
        {
            InternetExplorer ie = new InternetExplorerClass();

            ie.Visible = true;
            SUIWindow ieWin    = new SUIWindow(new IntPtr(ie.HWND));
            SUIIE     instance = new SUIIE(ie);

            instance.ieWin = ieWin;
            Object obj = new Object();

            ie.Navigate(URL, ref obj, ref obj, ref obj, ref obj);
            if (instance.WaitingForLoadComplete())
            {
                instance.IEWin.Maximized = true;
                return(instance);
            }
            return(null);
        }
예제 #9
0
        // Add this method for those situation where we need longer timeout to wait for window!
        public static SUIWindow WaitingForWindow(string caption, int timeout)
        {
            SUIWindow waitingForwin = null;

            try
            {
                while (waitingForwin == null && timeout-- > 0)
                {
                    SUISleeper.Sleep(1000);
                    waitingForwin = DesktopWindow.FindChildWindowByText(caption);
                }
            }
            catch (Exception e)
            {
                throw new SUIGetWindowException(e);
            }

            return(waitingForwin);
        }
예제 #10
0
 public SUIWindow FindChildWindow(string className, string winText)
 {
     try
     {
         return(SUIWindow.FindSMARTUIWindow(this, className, winText));
     }
     catch
     {
         if (className.StartsWith("BCGP"))
         {
             string optionname = className.Replace("BCGP", "BCG");
             return(SUIWindow.FindSMARTUIWindow(this, optionname, winText));
         }
         else
         {
             return(null);
         }
     }
 }
예제 #11
0
        public SUIBitmap GetClientArea()
        {
            IEWin.BringToTopMost();
            SUIWindow client = null;

            if (SUIIE.Version == 6)
            {
                client = IEWin.FindChildWindow("Shell DocObject View", string.Empty);
            }
            else
            {
                SUIWindow temp = IEWin.FindChildWindow("TabWindowClass", IEWin.WindowText);
                client = temp.FindChildWindow("Shell DocObject View", string.Empty);
            }
            if (client != null)
            {
                SUIBitmap clientImage = SUIImage.GetImageFromWindow(client);
                return(clientImage);
            }
            return(null);
        }
예제 #12
0
 private int CloseDialog(IntPtr hwnd, int lParam)
 {
     try
     {
         if (hwnd != null)
         {
             SUIWindow child  = new SUIWindow(hwnd);
             SUIWindow parent = child.Parent;
             if (parent != null)
             {
                 if ((child.IsDialog || child.IsWinForm) && (parent.WindowHandle.Equals(this.hwnd)))
                 {
                     child.Close();
                 }
             }
         }
     }
     catch (Exception e)
     {
     }
     return(1);
 }
예제 #13
0
        public static SUIWindow WaitingForWindow(string matchCaption, bool isRegularExpression, int timeout)
        {
            if (!isRegularExpression)
            {
                return(WaitingForWindow(matchCaption, timeout));
            }

            SUIWindow waitingForwin = null;
            Regex     reg           = new Regex(matchCaption);

            while (waitingForwin == null && timeout-- > 0)
            {
                SUISleeper.Sleep(1000);
                if (matchCaption.Equals(string.Empty))
                {
                    waitingForwin = DesktopWindow.FindChildWindowByText(matchCaption);
                    SUIWindow temp = SUIWindow.GetForegroundWindow();
                    if (!waitingForwin.WindowHandle.Equals(temp.WindowHandle))
                    {
                        waitingForwin = temp;
                    }
                }

                else
                {
                    foreach (SUIWindow win in DesktopWindow.Items)
                    {
                        if (SUIWinAPIs.IsWindowVisible(win.WindowHandle) && reg.IsMatch(win.WindowText))
                        {
                            waitingForwin = win;
                            break;
                        }
                    }
                }
            }
            return(waitingForwin);
        }
예제 #14
0
 // set SMARTUIWindow in foreground
 public static void SetForegroundWindow(SUIWindow sui)
 {
     SUIWinAPIs.SetForegroundWindow(sui.WindowHandle);
 }
예제 #15
0
 public SUIWindow FindChildWindowByText(string winText)
 {
     return(SUIWindow.FindSMARTUIWindow(this, null, winText));
 }
예제 #16
0
파일: SUIWindow.cs 프로젝트: a19284/SmartUI
 // set SMARTUIWindow in foreground
 public static void SetForegroundWindow(SUIWindow sui)
 {
     SUIWinAPIs.SetForegroundWindow(sui.WindowHandle);
 }
예제 #17
0
파일: SUIWindow.cs 프로젝트: a19284/SmartUI
 private int CloseDialog(IntPtr hwnd, int lParam)
 {
     try
     {
         if (hwnd != null)
         {
             SUIWindow child = new SUIWindow(hwnd);
             SUIWindow parent = child.Parent;
             if (parent != null)
             {
                 if ((child.IsDialog || child.IsWinForm) && (parent.WindowHandle.Equals(this.hwnd)))
                 {
                     child.Close();
                 }
             }
         }
     }
     catch (Exception e)
     {
     }
     return 1;
 }
예제 #18
0
 public SUIWindow FindChildWindow(SUIWindow childAfter, string className, string winText)
 {
     return(SUIWindow.FindSMARTUIWindow(this, childAfter, className, winText));
 }
예제 #19
0
        //If needMax != 0, we will maxmize the main window.
        public void Start(int needMax)
        {
            if (_parameters == null)
            {
                return;
            }
            if (_process != null)
            {
                return;
            }

            DateTime startTime = DateTime.Now;

            string workingDirectory;

            if (_parameters.ExePath == null)
            {
                workingDirectory = _parameters.ExePath;
            }
            else
            {
                workingDirectory = _parameters.ExePath.Substring(0, Strings.InStrRev(_parameters.ExePath, @"\", -1, CompareMethod.Binary));
            }

            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.WindowStyle      = ProcessWindowStyle.Normal;
            startInfo.FileName         = _parameters.ExePath;
            startInfo.Arguments        = _parameters.Arguments;
            startInfo.WorkingDirectory = workingDirectory;
            startInfo.ErrorDialog      = false;
            startInfo.UseShellExecute  = false; //if vista, set it to true

            //start the process and get the process info
            _process = Process.Start(startInfo);

            if (_parameters.HasWindow)
            {
                int timeOut;
                _process.WaitForInputIdle(_parameters.TimeOut);
                _process.Refresh();

                timeOut = _parameters.TimeOut;
                do
                {
                    if (_process.MainWindowHandle != IntPtr.Zero)
                    {
                        break;
                    }
                    _process.Refresh();
                    timeOut -= 1000;
                    SUISleeper.Sleep(1000);
                }while (timeOut >= 0);

                if (_parameters.MainWindowClass != null && _parameters.MainWindowClass != string.Empty) // try to ignore the splash window
                {
                    //_mainWindow = SUIWindow.WaitingForWindow(para.MainWindowClass, para.TimeOut/1000);
                    timeOut = _parameters.TimeOut;
                    do
                    {
                        _process.Refresh();
                        SUIWindow tempWindow;
                        try
                        {
                            tempWindow = new SUIWindow(_process.MainWindowHandle);
                        }
                        catch (Exception e)
                        {
                            tempWindow = null;
                        }
                        if (tempWindow != null && tempWindow.ClassName.Contains(_parameters.MainWindowClass))
                        {
                            _mainWindow = tempWindow;
                            break;
                        }
                        timeOut -= 1000;
                        SUISleeper.Sleep(1000);
                    }while (timeOut >= 0);
                }
                else
                {
                    //_mainWindow = SUIWindow.WaitingForWindow(para.MainWindowClass, para.TimeOut/1000);
                    timeOut = _parameters.TimeOut;
                    do
                    {
                        _process.Refresh();
                        SUIWindow tempWindow;
                        try
                        {
                            tempWindow = new SUIWindow(_process.MainWindowHandle);
                        }
                        catch (Exception e)
                        {
                            tempWindow = null;
                        }

                        if (tempWindow != null)
                        {
                            _mainWindow = tempWindow;
                            break;
                        }
                        timeOut -= 1000;
                        SUISleeper.Sleep(1000);
                    }while (timeOut >= 0);
                }
            }
            DateTime endTime = DateTime.Now;

            CalculatePerformanceIndex(startTime, endTime);

            this.BringToForeground(needMax);
            SUISleeper.Sleep(2000);
            ClosePopupWindow();
        }
예제 #20
0
파일: SUIWindow.cs 프로젝트: a19284/SmartUI
 public bool IsCenterOfBackground(SUIWindow backGroundWin)
 {
     int backGroundLeft = backGroundWin.X;
     int backGroundTop = backGroundWin.Y;
     int backGroundRight = backGroundWin.Width;
     int backGroundBottom = backGroundWin.Height;
     if (
              Math.Abs(((backGroundLeft + backGroundRight) / 2 - (this.X + this.Width) / 2)) < 10 &&
              Math.Abs(((backGroundTop + backGroundBottom) / 2 - (this.Y + this.Height) / 2)) < 10
        )
     {
         return true;
     }
     return false;
 }
예제 #21
0
파일: SUIWindow.cs 프로젝트: a19284/SmartUI
 public static SUIWindow GetForegroundWindow()
 {
     SUIWindow sui = null;
     IntPtr ptr = SUIWinAPIs.GetForegroundWindow();
     if (ptr.Equals(IntPtr.Zero))
     {
         return null;
     }
     sui = new SUIWindow(ptr);
     return sui;
 }
예제 #22
0
파일: SUIWindow.cs 프로젝트: a19284/SmartUI
 public static void MinimizeAllWindow(SUIWindow exception)
 {
     SUIWindowCollection windows = SUIWindow.DesktopWindow.Items;
     foreach (SUIWindow win in windows)
     {
         if (exception != null)
         {
             // If current window is the exception window or child window of the exception window.
             SUIWindow parent = win.Parent;
             if (win.WindowHandle.Equals(exception.WindowHandle) || (parent != null && parent.WindowHandle.Equals(exception.WindowHandle)))
             {
                 continue;
             }
         }
         win.Minimized = true;
     }
 }
예제 #23
0
파일: SUIWindow.cs 프로젝트: a19284/SmartUI
 public SUIWindow(SUIWindow win)
 {
     if (win == null || win.WindowHandle == null || win.WindowHandle.Equals(IntPtr.Zero))
         throw new SUINullWindowException();//Exception(SUIBaseErrorMessages.Window_CannotInitializeWindow);
     this.hwnd = win.WindowHandle;
 }
예제 #24
0
파일: SUIWindow.cs 프로젝트: a19284/SmartUI
 public SUIWindow FindChildWindow(SUIWindow childAfter, string className, string winText)
 {
     return SUIWindow.FindSMARTUIWindow(this, childAfter, className, winText);
 }
예제 #25
0
        // add smart ui to collection
        public void Add(IntPtr hwnd)
        {
            SUIWindow sui = new SUIWindow(hwnd);

            this.InnerList.Add(sui);
        }
예제 #26
0
파일: SUIWindow.cs 프로젝트: a19284/SmartUI
        public static SUIWindow FindSMARTUIWindow(SUIWindow parent, SUIWindow childAfter, string classname, string windowtext)
        {
            if (childAfter == null)
                return FindSMARTUIWindow(parent, classname, windowtext);

            SUIWindow sui = null;
            IntPtr ptr = SUIWinAPIs.FindWindowEx(parent.hwnd, childAfter.hwnd, classname, windowtext);
            if (!ptr.Equals(IntPtr.Zero))
            {
                sui = new SUIWindow(ptr);
                //With below statement, we could avoid the invisible windows.
                if (!SUIWinAPIs.IsWindowVisible(ptr))
                {
                    sui = FindSMARTUIWindow(parent, sui, classname, windowtext);
                }
            }
            return sui;
        }
예제 #27
0
파일: SUIIE.cs 프로젝트: a19284/SmartUI
 public static SUIIE CreateIEWithURL(string URL)
 {
     InternetExplorer ie = new InternetExplorerClass();
     ie.Visible = true;
     SUIWindow ieWin = new SUIWindow(new IntPtr(ie.HWND));
     SUIIE instance = new SUIIE(ie);
     instance.ieWin = ieWin;
     Object obj = new Object();
     ie.Navigate(URL, ref obj, ref obj, ref obj, ref obj);
     if (instance.WaitingForLoadComplete())
     {
         instance.IEWin.Maximized = true;
         return instance;
     }
     return null;
 }
예제 #28
0
파일: SUIWindow.cs 프로젝트: a19284/SmartUI
 // add smart ui to collection
 public void Add(IntPtr hwnd)
 {
     SUIWindow sui = new SUIWindow(hwnd);
     this.InnerList.Add(sui);
 }
예제 #29
0
파일: SUIApp.cs 프로젝트: a19284/SmartUI
        //If needMax != 0, we will maxmize the main window.
        public void Start(int needMax)
        {
            if (_parameters == null)
                return;
            if (_process != null)
                return;

            DateTime startTime = DateTime.Now;

            string workingDirectory;
            if (_parameters.ExePath == null)
            {
                workingDirectory = _parameters.ExePath;
            }
            else
            {
                workingDirectory = _parameters.ExePath.Substring(0, Strings.InStrRev(_parameters.ExePath, @"\", -1, CompareMethod.Binary));
            }

            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.WindowStyle = ProcessWindowStyle.Normal;
            startInfo.FileName = _parameters.ExePath;
            startInfo.Arguments = _parameters.Arguments;
            startInfo.WorkingDirectory = workingDirectory;
            startInfo.ErrorDialog = false;
            startInfo.UseShellExecute = false; //if vista, set it to true

            //start the process and get the process info
            _process = Process.Start(startInfo);

            if (_parameters.HasWindow)
            {
                int timeOut;
                _process.WaitForInputIdle(_parameters.TimeOut);
                _process.Refresh();

                timeOut = _parameters.TimeOut;
                do
                {
                    if (_process.MainWindowHandle != IntPtr.Zero)
                    {
                        break;
                    }
                    _process.Refresh();
                    timeOut -= 1000;
                    SUISleeper.Sleep(1000);

                }
                while (timeOut >= 0);

                if (_parameters.MainWindowClass != null && _parameters.MainWindowClass != string.Empty) // try to ignore the splash window
                {
                    //_mainWindow = SUIWindow.WaitingForWindow(para.MainWindowClass, para.TimeOut/1000);
                    timeOut = _parameters.TimeOut;
                    do
                    {
                        _process.Refresh();
                        SUIWindow tempWindow;
                        try
                        {
                            tempWindow = new SUIWindow(_process.MainWindowHandle);
                        }
                        catch (Exception e)
                        {
                            tempWindow = null;
                        }
                        if (tempWindow != null && tempWindow.ClassName.Contains(_parameters.MainWindowClass))
                        {
                            _mainWindow = tempWindow;
                            break;
                        }
                        timeOut -= 1000;
                        SUISleeper.Sleep(1000);
                    }
                    while (timeOut >= 0);
                }
                else
                {
                    //_mainWindow = SUIWindow.WaitingForWindow(para.MainWindowClass, para.TimeOut/1000);
                    timeOut = _parameters.TimeOut;
                    do
                    {
                        _process.Refresh();
                        SUIWindow tempWindow;
                        try
                        {
                            tempWindow = new SUIWindow(_process.MainWindowHandle);
                        }
                        catch (Exception e)
                        {
                            tempWindow = null;
                        }

                        if (tempWindow != null)
                        {
                            _mainWindow = tempWindow;
                            break;
                        }
                        timeOut -= 1000;
                        SUISleeper.Sleep(1000);
                    }
                    while (timeOut >= 0);
                }
            }
            DateTime endTime = DateTime.Now;
            CalculatePerformanceIndex(startTime, endTime);

            this.BringToForeground(needMax);
            SUISleeper.Sleep(2000);
            ClosePopupWindow();
        }