Пример #1
0
        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));
        }
Пример #2
0
        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);
        }
Пример #3
0
        // 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);
        }
Пример #4
0
        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);
        }
Пример #5
0
 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.");
     }
 }
Пример #6
0
        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);
        }
Пример #7
0
        //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);
        }
Пример #8
0
        public string GetTextByIndex(int index)
        {
            StringBuilder itemText = new StringBuilder();

            SUIWinAPIs.SendMessage(WindowHandle, SUIMessage.LB_GETTEXT, index, itemText);
            return(itemText.ToString());
        }
Пример #9
0
        //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));
        }
Пример #10
0
        public void Resize(int width, int height)
        {
            Rectangle r = new Rectangle();

            SUIWinAPIs.GetWindowRect(this.hwnd, out r);
            Resize(r.X, r.Y, width, height);
        }
Пример #11
0
        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());
        }
Пример #12
0
 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);
 }
Пример #13
0
        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));
        }
Пример #14
0
 // used to continue enumeration
 protected virtual bool OnWindowEnum(IntPtr hWnd)
 {
     if (SUIWinAPIs.IsWindowVisible(hWnd))
     {
         items.Add(hWnd);
     }
     return(true);
 }
Пример #15
0
        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());
        }
Пример #16
0
        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.");
            }
        }
Пример #17
0
        public SUIWindow GetDialogItem(int dlgItemID)
        {
            IntPtr itemHandle = SUIWinAPIs.GetDlgItem(WindowHandle, dlgItemID);

            if (itemHandle != null && !itemHandle.Equals(IntPtr.Zero))
            {
                return(new SUIWindow(itemHandle));
            }
            return(null);
        }
Пример #18
0
        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);
        }
Пример #19
0
        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.");
            }
        }
Пример #20
0
        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);
        }
Пример #21
0
        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);
        }
Пример #22
0
 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);
 }
Пример #23
0
        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);
        }
Пример #24
0
        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;
        }
Пример #25
0
 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);
     }
 }
Пример #26
0
        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());
        }
Пример #27
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);
        }
Пример #28
0
 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();
     }
 }
Пример #29
0
 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);
     }
 }
Пример #30
0
 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!");
         }
     }
 }