public SUIWindow ClickToGetEditControl() { Click(); SUISleeper.Sleep(2000); RECT rect = Rect; int x = ListView.X + rect.left + 5; int y = ListView.Y + rect.top + 5; IntPtr handle = SUIWinAPIs.WindowFromPoint(new Point(x, y)); if (handle == null || handle.Equals(IntPtr.Zero) || handle.Equals(ListView.WindowHandle)) { throw new SUIException("No edit control found!"); } SUIWindow window = new SUIWindow(handle); while (true) { if (window.Parent == null) { throw new SUIException("No edit control found!"); } if (window.Parent.WindowHandle.Equals(ListView.WindowHandle)) { break; } window = window.Parent; } return(window); }
public static SUIPopupMenu FindPopupMenu() //for all the popup menu { try { int timeout = 10; int timeCounter = 0; while (true) { SUISleeper.Sleep(500); IntPtr popupWindowHandle = SUIWinAPIs.FindWindowEx(IntPtr.Zero, IntPtr.Zero, "#32768", string.Empty); if (!popupWindowHandle.Equals(IntPtr.Zero)) { return(new SUIPopupMenu(popupWindowHandle)); } timeCounter++; if (timeCounter > timeout) { throw new Exception(); } } } catch (Exception) { throw new Exception("No menu popup."); } }
public void ClickSelect(int index) { if (this.SelectedIndex != index) { if (IsDropDown) { SUIMouse.MouseClick(this, this.Width - this.X - 5, (this.Height - this.Y) / 2); } else { this.Focus(); } int offset = index - this.SelectedIndex; if (offset > 0) { for (int i = 0; i < offset; i++) { SUIKeyboard.Type(SUI.Base.Win.SUIKeyboard.VK.DOWN); } } else { offset = Math.Abs(offset); for (int j = 0; j < offset; j++) { SUIKeyboard.Type(SUI.Base.Win.SUIKeyboard.VK.UP); } } SUISleeper.Sleep(500); if (IsDropDown) { SUIKeyboard.Type(SUI.Base.Win.SUIKeyboard.VK.RETURN); } } }
public static Point GetPositionFromTextIndex(IntPtr HWnd, string text, int index) { string processedText = text; if (SUIUtil.IsCurrentOSVista) { SUIWindow win = new SUIWindow(HWnd); if (!win.ClassName.Equals("SysListView32")) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < text.Length; i++) { char temp = (char)(text[i] - 29); builder.Append(temp); } processedText = builder.ToString(); } } Point result = new Point(-1, -1); try { SUISleeper.Sleep(2000); result = GetPointFromTextIndex(HWnd, processedText, index); } catch { Debug.WriteLine("GetPositionFromText ERROR."); } return(result); }
public SUIMsoCommandBarPopup PopupMenu(int index) { if (ItemList[index] != null) { ItemList[index].Click(); SUISleeper.Sleep(500); SUIWinAPIs.EnumWindows(new EnumSMARTUIWindowsProc(this.FindPopupMenu), 0); return(popupedMenu); } return(null); }
public void ShowShortCutIndicators() { //Only if we are working on a dialog, indicators are supposed to display. if (IsDialog) { SUIKeyboard.Type(SUIKeyboard.VK.MENU); //Type "Alt" key for twice to ensure that we could see indicators. SUIKeyboard.Type(SUIKeyboard.VK.MENU); SUISleeper.Sleep(1000); } }
public void DoubleClick(string rowName, string columnName) { Point p1 = SUIAccessibility.GetPositionFromText(WindowHandle, rowName); SUISleeper.Sleep(2000); if (p1.X < 0 || p1.Y < 0) { throw new Exception("can not locate string" + rowName); } Point p2 = SUIAccessibility.GetPositionFromText(WindowHandle, columnName); if (p2.X < 0 || p2.Y < 0) { throw new Exception("can not locate string" + columnName); } ClickWindow(p2.X, p1.Y + 3, 3); }
// 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); }
//Sometimes, it needs a few seconds to initialize context menu and show it. //So I add a timeout parameter for this operation. public static SUIPopupMenu MouseRightClick(SUIWindow window, string strWindowsText, int x, int y, int timeout) { SUIMouse.MouseRightClick(window, x, y); SUIWindow win = null; while (win == null && timeout > 0) { SUISleeper.Sleep(200); win = SUIWindow.DesktopWindow.FindChildWindow("#32768", strWindowsText); timeout--; } if (win == null) { throw new SUIException("Fail to find context menus!"); } return(new SUIPopupMenu(win)); }
//Sometimes, it needs a few seconds to initialize context menu and show it. //So I add a timeout parameter for this operation. public static SUIMsoCommandBarPopup MouseRightClick(SUIWindow window, string strWindowsText, int x, int y, int timeout) { SUIMouse.MouseRightClick(window, x, y); SUIWindow win = null; while (win == null && timeout > 0) { SUISleeper.Sleep(200); win = SUIWindow.DesktopWindow.FindChildWindow(WindowClass, strWindowsText); timeout--; } if (win == null) { return(null); } return(new SUIMsoCommandBarPopup(win)); }
public SUIMsoCommandBarPopup PopupMenu(string itemText) { MsoCommandBarItem target = null; foreach (MsoCommandBarItem item in ItemList) { if (item != null && item.Name.Equals(itemText)) { target = item; break; } } if (target != null) { target.Click(); SUISleeper.Sleep(500); SUIWinAPIs.EnumWindows(new EnumSMARTUIWindowsProc(this.FindPopupMenu), 0); return(popupedMenu); } return(null); }
public bool WaitingForLoadComplete() { int checksequence = 60; while (true) { SUISleeper.Sleep(2000); if (ie.ReadyState == tagREADYSTATE.READYSTATE_COMPLETE) { return(true); } if (checksequence > 0) { checksequence--; } else { return(false); } } }
// Comment out this method and we have an alternative solution. //private static SUIIE GetIE() //{ // Object o = Interaction.CreateObject("Shell.Application.1", null); // IShellDispatch4 shell = (IShellDispatch4)o; // IShellWindows windows = (IShellWindows)shell.Windows(); // for (int i = 0; i < windows.Count; i++) // { // Object obj = windows.Item(i); // if (Information.TypeName(obj).Equals("IWebBrowser2")) // { // IWebBrowser2 browser = (IWebBrowser2)obj; // SUIWindow ieWin = new SUIWindow(new IntPtr(browser.HWND)); // if (ieWin.WindowText.Contains(IETitleSuffix)) // { // SUIIE instance = new SUIIE(browser); // instance.ieWin = ieWin; // return instance; // } // } // } // return null; //} public static SUIIE WaitingForIEWindow(string IETitle) { // Interestingly, we cannot catch IE7 window with below logic on Vista // without Administrative previlege. ShellWindows windows = new ShellWindowsClass(); int count = windows.Count; InternetExplorer myIE = null; while (myIE == null) { SUISleeper.Sleep(1000); if (windows.Count >= count + 1) { foreach (InternetExplorer tmpIE in windows) { if (tmpIE.FullName.EndsWith(IEProcess, true, null)) { myIE = tmpIE; } } } } SUIIE ie = new SUIIE(myIE); ie.ieWin = new SUIWindow(new IntPtr(myIE.HWND)); if (ie.WaitingForLoadComplete()) { //If the specified title is a null string, we will return the default IE window we find. if (IETitle == null || ie.IEWin.WindowText.Equals(IETitle + SUIIE.IETitleSuffix)) { ie.IEWin.Maximized = true; return(ie); } } return(null); }
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); }
public void SelectText(string text, int index) { Graphics g = Graphics.FromHwnd(WindowHandle); IntPtr hdc = g.GetHdc(); Size size = new Size(); SUIWinAPIs.GetTextExtentPoint32(hdc, text, text.Length, out size); g.ReleaseHdc(); Point p = SUIAccessibility.GetPositionFromTextIndex(this.WindowHandle, text, index); if (p.X < 0 || p.Y < 0) { SUISleeper.Sleep(2000); p = SUIAccessibility.GetPositionFromTextIndex(this.WindowHandle, text, index); } if (p.X > 0 && p.Y > 0) { SUIMouse.MouseClick(this, p.X + size.Width / 2, p.Y + size.Height / 2); } else { throw new Exception("Can not locate expected string " + text + "."); } }
public virtual void Quit() { SUISleeper.Sleep(1000); MainWindow.CloseChildModalDialog(); this.Process.CloseMainWindow(); }
public void ClickWindow(int x, int y, int nFlags) { this.Focus(); SUISleeper.Sleep(2000); SUIMouse.MouseClick(this, x, y, nFlags); }
public SUIDotNetContextMenuStrip PopupSubMenu(int clickedIndex) { this.Click(clickedIndex); SUISleeper.Sleep(500); return(FindContextMenu()); }
public static SUIBitmap GetImageFromWindow(SUIWindow sui, bool withCursor) { if (null != sui) { SUISleeper.Sleep(2000); //make sure paint compldte! //Rectangle rDialog = new Rectangle(); try { if (!sui.ClassName.Equals("#32768")) { sui.BringToTopMost(); sui.ShowShortCutIndicators(); if (!withCursor) { SUIWinAPIs.SetCursorPos(SUIWindow.DesktopWindow.Width / 2, 0);// Set Cursor at top mid of screen } } } catch (Exception e) { throw new SUIGetImageException("Win32 SDK Platform Exception!", e); } IntPtr hdcSrc = IntPtr.Zero; IntPtr hdcDest = IntPtr.Zero; IntPtr hBitmap = IntPtr.Zero; Bitmap image = null; try { //index to solve the problem of GDR+ when run IE 2 times in one case. index = ((index % 10) + 1); //SUIWinAPIs.GetWindowRect(sui.WindowHandle, out rDialog); int buffer = 0; if ((SUIUtil.IsCurrentOSVista || SUIUtil.IsCurrentOSXP) && sui.IsWinForm && sui.Maximized) { buffer = 8; // under vista need cut a little height of window } hdcSrc = SUIWinAPIs.GetWindowDC(sui.WindowHandle); hdcDest = SUIWinAPIs.CreateCompatibleDC(hdcSrc); hBitmap = SUIWinAPIs.CreateCompatibleBitmap(hdcSrc, sui.Width - sui.X, sui.Height - sui.Y - buffer); SUIWinAPIs.SelectObject(hdcDest, hBitmap); SUIWinAPIs.BitBlt(hdcDest, 0, 0, sui.Width - sui.X, sui.Height - sui.Y - buffer, hdcSrc, 0, 0, 0x00CC0020); image = new Bitmap(Image.FromHbitmap(hBitmap), Image.FromHbitmap(hBitmap).Width, Image.FromHbitmap(hBitmap).Height); //Draw cursor image if (withCursor) { int cursorX = 0, cursorY = 0; SUIBitmap cursorBmp = GetCursorImage(ref cursorX, ref cursorY); if (cursorBmp != null) { Bitmap cBmp = cursorBmp.Bitmap; Rectangle r = new Rectangle(cursorX - sui.X, cursorY - sui.Y, cBmp.Width, cBmp.Height); Graphics g = Graphics.FromImage(image); g.DrawImage(cBmp, r); g.Flush(); cBmp.Dispose(); } } image.Save(tmpFile + index + tmpFileSuffix); image.Dispose(); //SaveImg(image,tmpFile,ImageFormat.Bmp); }catch (Exception e) { throw new SUIGetImageException("Win32 SDK Platform Exception!", e); }finally { if (!hdcSrc.Equals(IntPtr.Zero)) { SUIWinAPIs.ReleaseDC(sui.WindowHandle, hdcSrc); } if (!hdcDest.Equals(IntPtr.Zero)) { SUIWinAPIs.DeleteDC(hdcDest); } if (!hBitmap.Equals(IntPtr.Zero)) { SUIWinAPIs.DeleteObject(hBitmap); } if (image != null) { image.Dispose(); } } SUIBitmap ImageOfWindow = SUIBitmap.LoadSUIBitmap(tmpFile + index + tmpFileSuffix); return(ImageOfWindow); } throw new SUIGetImageException("Parameter SUIWindow sui is Null"); }
public void Click() { Focus(); SUISleeper.Sleep(1000); SUIMouse.MouseClick(this, (Width - X) / 2, (Height - Y) / 2); }
//Send Command public void Execute() { //Here, we use PostMessage instead of SendMessage to avoid current process blocked. SUIWinAPIs.PostMessage(toolbar.WindowHandle, SUIMessage.WM_COMMAND, TBBUTTON.idCommand, 0); SUISleeper.Sleep(1000); }
public void MouseMoveTo() { SUIMouse.MouseMove(new SUIWindow(toolbar), (int)((Rectangle.X + Rectangle.Width) / 2), (int)((Rectangle.Y + Rectangle.Height) / 2)); SUISleeper.Sleep(1000); }
internal void ExpandNode(SUITreeViewNode node, int flag) { SUIWinAPIs.PostMessage(WindowHandle, SUIMessage.TVM_EXPAND, new IntPtr(flag), node.hItem); SUISleeper.Sleep(500); }
//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 void ClickToSelect(int index) { SetTopIndex(index); SUISleeper.Sleep(200); ClickItem(index); }