Example #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;
 }
Example #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);
     }
 }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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);
        }
Example #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;
            }
        }
Example #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);
        }
Example #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);
        }
Example #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);
         }
     }
 }
Example #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);
        }
Example #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);
 }
Example #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);
        }
Example #14
0
 // set SMARTUIWindow in foreground
 public static void SetForegroundWindow(SUIWindow sui)
 {
     SUIWinAPIs.SetForegroundWindow(sui.WindowHandle);
 }
Example #15
0
 public SUIWindow FindChildWindowByText(string winText)
 {
     return(SUIWindow.FindSMARTUIWindow(this, null, winText));
 }
Example #16
0
 // set SMARTUIWindow in foreground
 public static void SetForegroundWindow(SUIWindow sui)
 {
     SUIWinAPIs.SetForegroundWindow(sui.WindowHandle);
 }
Example #17
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;
 }
Example #18
0
 public SUIWindow FindChildWindow(SUIWindow childAfter, string className, string winText)
 {
     return(SUIWindow.FindSMARTUIWindow(this, childAfter, className, winText));
 }
Example #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();
        }
Example #20
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;
 }
Example #21
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;
 }
Example #22
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;
     }
 }
Example #23
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;
 }
Example #24
0
 public SUIWindow FindChildWindow(SUIWindow childAfter, string className, string winText)
 {
     return SUIWindow.FindSMARTUIWindow(this, childAfter, className, winText);
 }
Example #25
0
        // add smart ui to collection
        public void Add(IntPtr hwnd)
        {
            SUIWindow sui = new SUIWindow(hwnd);

            this.InnerList.Add(sui);
        }
Example #26
0
        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;
        }
Example #27
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;
 }
Example #28
0
 // add smart ui to collection
 public void Add(IntPtr hwnd)
 {
     SUIWindow sui = new SUIWindow(hwnd);
     this.InnerList.Add(sui);
 }
Example #29
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();
        }