public bool BringToTopMost() { Rectangle rec = new Rectangle(); SUIWinAPIs.GetWindowRect(this.hwnd, out rec); return(SUIWinAPIs.SetWindowPos(this.hwnd, SUIMessage.HWND_TOPMOST, rec.X, rec.Y, rec.Width - rec.X, rec.Height - rec.Y, SUIMessage.SWP_NOMOVE)); }
public void MoveWindow(int x, int y) { Rectangle r = new Rectangle(); SUIWinAPIs.GetWindowRect(this.hwnd, out r); Resize(x, y, r.Width - r.X, r.Height - r.Y); }
// Gets the Internet Explorer IHTMLDocument2 object for the given // IE Server control window handle // The class name of this window should be "Internet Explorer_Server" private static IHTMLDocument2 GetIEDocumentFromWindow(SUIWindow window) { if (!window.ClassName.Equals("Internet Explorer_Server")) { throw new SUIException("Unable to get IHTMLDocument object from this window!"); } IntPtr lResult; int lMsg; IHTMLDocument2 htmlDocument = null; if (window.WindowHandle != IntPtr.Zero) { // Register the WM_HTML_GETOBJECT message so it can be used // to communicate with the Internet Explorer instance lMsg = SUIWinAPIs.RegisterWindowMessage("WM_HTML_GETOBJECT"); // Sends the above registered message to the IE window and // waits for it to process it SUIWinAPIs.SendMessageTimeout(window.WindowHandle, lMsg, IntPtr.Zero, IntPtr.Zero, SUIWinAPIs.SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 1000, out lResult); if (lResult != IntPtr.Zero) { // Casts the value returned by the IE window into //an IHTMLDocument2 interface htmlDocument = SUIWinAPIs.ObjectFromLresult(lResult, typeof(IHTMLDocument).GUID, IntPtr.Zero) as IHTMLDocument2; } if (htmlDocument == null) { throw new SUIException("Unable to get IHTMLDocument object from this window!"); } } return(htmlDocument); }
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 static SUIBitmap GetCursorImage(ref int x, ref int y) { Bitmap bmp; IntPtr hicon; CURSORINFO ci = new CURSORINFO(); ICONINFO icInfo; ci.cbSize = Marshal.SizeOf(ci); if (SUIWinAPIs.GetCursorInfo(out ci)) { if (ci.flags == SUIMessage.CURSOR_SHOWING) { hicon = SUIWinAPIs.CopyIcon(ci.hCursor); if (SUIWinAPIs.GetIconInfo(hicon, out icInfo)) { x = ci.ptScreenPos.X - ((int)icInfo.xHotspot); y = ci.ptScreenPos.Y - ((int)icInfo.yHotspot); Icon ic = Icon.FromHandle(hicon); bmp = ic.ToBitmap(); return(new SUIBitmap(bmp, null)); } } } return(null); }
//Zero based public RECT GetItemRECT(int index) { if (index < 0 || index >= Count) { throw new SUIException("Index is out of range!"); } RECT rec = new RECT(); IntPtr ptr = IntPtr.Zero; try { ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(typeof(RECT))); SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.LB_GETITEMRECT, index, ptr); rec = (RECT)Marshal.PtrToStructure(ptr, typeof(RECT)); } catch (Exception e) { throw new SUIException("Error getting item rectangle!", e); } finally { Marshal.FreeCoTaskMem(ptr); } return(rec); }
public string GetTextByIndex(int index) { StringBuilder itemText = new StringBuilder(); SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.LB_GETTEXT, index, itemText); return(itemText.ToString()); }
//Index of the item to begin the search with, //or -1 to find the first item that matches the specified flags. //The specified item itself is excluded from the search. internal SUIListViewItem GetNextItem(int startItemIndex, int flag) { LVITEM item = new LVITEM(); item.iItem = SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.LVM_GETNEXTITEM, startItemIndex, flag).ToInt32(); return(new SUIListViewItem(this, item)); }
public void Resize(int width, int height) { Rectangle r = new Rectangle(); SUIWinAPIs.GetWindowRect(this.hwnd, out r); Resize(r.X, r.Y, width, height); }
public string GetSelectItem() { int selectedItem = SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.LB_GETCURSEL, IntPtr.Zero, IntPtr.Zero); SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.LB_GETTEXT, selectedItem, itemText); return(itemText.ToString()); }
public void SelectNode(SUITreeViewNode node) { if (node.IsNullNode) { throw new SUIException("Cannot select NULL TreeView node!"); } SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.TVM_SELECTITEM, new IntPtr(SUIMessage.TVGN_CARET), node.hItem); }
internal SUITreeViewNode GetNextItem(IntPtr currentItem, int flag) { IntPtr itemPtr = new IntPtr(SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.TVM_GETNEXTITEM, new IntPtr(flag), currentItem)); TVITEM item = new TVITEM(); item.hItem = itemPtr; return(new SUITreeViewNode(this, item)); }
// used to continue enumeration protected virtual bool OnWindowEnum(IntPtr hWnd) { if (SUIWinAPIs.IsWindowVisible(hWnd)) { items.Add(hWnd); } return(true); }
public int GetItemHeight(int index) { if (index < 0 || index >= Count) { throw new SUIException("Index is out of range!"); } return(SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.LB_GETITEMHEIGHT, 0, 0).ToInt32()); }
public SUIAccessibility(IntPtr HWnd, AccType type) { IntPtr Result = SUIWinAPIs.AccessibleObjectFromWindow(HWnd, (int)type, ref GuidOfIAcc, ref IAcc); if (!Result.Equals(IntPtr.Zero)) { throw new Exception("Object does not support IAccessible."); } }
public SUIWindow GetDialogItem(int dlgItemID) { IntPtr itemHandle = SUIWinAPIs.GetDlgItem(WindowHandle, dlgItemID); if (itemHandle != null && !itemHandle.Equals(IntPtr.Zero)) { return(new SUIWindow(itemHandle)); } return(null); }
public void Focus() { //SUIWindow.SetForegroundWindow(this); IntPtr currentId = SUIWinAPIs.GetCurrentThreadId(); int processid = 0; IntPtr attachId = SUIWinAPIs.GetWindowThreadProcessId(WindowHandle, ref processid); SUIWinAPIs.AttachThreadInput(currentId, attachId, 1); SUIWinAPIs.SetFocus(WindowHandle); }
public SUITabControl(IntPtr hWnd) : base(hWnd) { IntPtr Result = SUIWinAPIs.AccessibleObjectFromWindow(hWnd, (int)AccType.Client, ref SUIAccessibility.GuidOfIAcc, ref IAcc); if (!Result.Equals(IntPtr.Zero)) { throw new Exception("Object does not support IAccessible."); } }
public int GetNodeState(int flag) { if (IsNullNode) { throw new SUIException("Cannot get state of NULL TreeView node!"); } int rv = SUIWinAPIs.SendMessage(TreeView.WindowHandle, SUIMessage.TVM_GETITEMSTATE, hItem, new IntPtr(flag)); return(rv); }
public int GetItemState(int flag) { if (IsInvalidItem) { throw new SUIException("Cannot get state of an invalid item!"); } int rv = SUIWinAPIs.SendMessage(ListView.WindowHandle, SUIMessage.LVM_GETITEMSTATE, Index, flag).ToInt32(); return(rv); }
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 Resize(int x, int y, int width, int height) { Rectangle rect = new Rectangle(x, y, x + width, y + height); SUIWinAPIs.AdjustWindowRectEx(ref rect, WindowStyle, (SUIWinAPIs.GetMenu(WindowHandle) != null), WindowExStyle); IntPtr hDWP = SUIWinAPIs.BeginDeferWindowPos(1); SUIWinAPIs.DeferWindowPos(hDWP, WindowHandle, SUIMessage.HWND_TOP, x, y, width, height, SUIMessage.SWP_SHOWWINDOW); SUIWinAPIs.EndDeferWindowPos(hDWP); }
public SUIAccessibility(Point p) { object o = new object(); IntPtr Result = SUIWinAPIs.AccessibleObjectFromPoint(p, ref IAcc, out o); if (!Result.Equals(IntPtr.Zero)) { throw new Exception("Object does not support IAccessible."); } childID = (int)o; }
public void UnselectAll() { if (IsMultipleSelect) { SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.LB_SETSEL, 0, new IntPtr(-1)); } else { SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.LB_SETCURSEL, -1, IntPtr.Zero); } }
public string GetDropdownListText(int index) { if (index < 0 || index >= DropdownListTextCount) { throw new SUIException("Index is out of range!"); } text = new StringBuilder(MaxLength); SUIWinAPIs.SendMessage(this.WindowHandle, SUIMessage.CB_GETLBTEXT, index, text); return(text.ToString()); }
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 void Click(bool isMessage) { if (isMessage) { SUIWinAPIs.PostMessage(this.WindowHandle, SUIMessage.WM_LBUTTONDOWN, 0, 0); SUIWinAPIs.PostMessage(this.WindowHandle, SUIMessage.WM_LBUTTONUP, 0, 0); } else { Click(); } }
public void Select(int index) { //The selection messages are different for single/multiple selection control. if (IsMultipleSelect) { UnselectAll(); MultipleSelect(index); } else { SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.LB_SETCURSEL, index, IntPtr.Zero); } }
public void RefreshControlList() { if (controlList != null) { try { SUIWinAPIs.EnumChildWindows(this.WindowHandle, new EnumSMARTUIWindowsProc(EnumControls), 0); } catch (Exception e) { throw new SUIException("Refresh Dialog ControlList failed!"); } } }