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; }
//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); } }
public static SUIWindow GetForegroundWindow() { SUIWindow sui = null; IntPtr ptr = SUIWinAPIs.GetForegroundWindow(); if (ptr.Equals(IntPtr.Zero)) { return(null); } sui = new SUIWindow(ptr); return(sui); }
// 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); }
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); }
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); }
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; } }
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); }
// 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); }
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); } } }
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); }
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); }
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); }
// set SMARTUIWindow in foreground public static void SetForegroundWindow(SUIWindow sui) { SUIWinAPIs.SetForegroundWindow(sui.WindowHandle); }
public SUIWindow FindChildWindowByText(string winText) { return(SUIWindow.FindSMARTUIWindow(this, null, winText)); }
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; }
public SUIWindow FindChildWindow(SUIWindow childAfter, string className, string winText) { return(SUIWindow.FindSMARTUIWindow(this, childAfter, className, winText)); }
//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(); }
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; }
public static SUIWindow GetForegroundWindow() { SUIWindow sui = null; IntPtr ptr = SUIWinAPIs.GetForegroundWindow(); if (ptr.Equals(IntPtr.Zero)) { return null; } sui = new SUIWindow(ptr); return sui; }
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; }
public SUIWindow FindChildWindow(SUIWindow childAfter, string className, string winText) { return SUIWindow.FindSMARTUIWindow(this, childAfter, className, winText); }
// add smart ui to collection public void Add(IntPtr hwnd) { SUIWindow sui = new SUIWindow(hwnd); this.InnerList.Add(sui); }
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; }
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; }
//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(); }