示例#1
0
        public static ComboBox CreateByIndex(IntPtr hWnd, IntPtr hWndWin, int indexBaseZero, ref int currIndex)
        {
            int           length    = WinAPI.GetWindowTextLength(hWnd);
            StringBuilder className = new StringBuilder(length + 1000);

            WinAPI.GetClassName(hWnd, className, className.Capacity);

            uint processid = 0;

            WinAPI.GetWindowThreadProcessId(hWnd, out processid);

            //Console.WriteLine(string.Format("{0} {1}", hWnd.ToString("x8"), className));

            if (className.ToString() != "ComboBox")
            {
                return(null);
            }

            if (currIndex != indexBaseZero)
            {
                currIndex++;
                return(null);
            }

            return((ComboBox)Activator.CreateInstance(typeof(ComboBox), hWnd, hWndWin, string.Format("Index[{0}]", indexBaseZero)));
        }
示例#2
0
            private string StringFormat(ref string tab)
            {
                string rslt = "";

                if (hWnd != IntPtr.Zero)
                {
                    int           length     = WinAPI.GetWindowTextLength(hWnd);
                    StringBuilder windowName = new StringBuilder(length + 1);
                    WinAPI.GetWindowText(hWnd, windowName, windowName.Capacity);

                    string winClass = WinAPI.GetWinClass(hWnd);

                    uint pid = 0;
                    WinAPI.GetWindowThreadProcessId(hWnd, out pid);

                    rslt += string.Format("HWND:{0}, WinText:{1}, ClassType:{2}, ProcessID:{3}", hWnd.ToString("X8"), windowName.ToString(), winClass, pid.ToString("X8")) + "\n";
                }

                tab += "    ";
                foreach (WinTree tree in subWin)
                {
                    rslt += tab + tree.StringFormat(ref tab);
                }

                tab = tab.Substring(0, tab.Length - 4);

                return(rslt);
            }
示例#3
0
        private static bool CheckByName(IntPtr hWnd, String name)
        {
            int           length     = WinAPI.GetWindowTextLength(hWnd);
            StringBuilder windowName = new StringBuilder(length + 1);

            WinAPI.GetWindowText(hWnd, windowName, windowName.Capacity);

            StringBuilder className = new StringBuilder(length + 1000);

            WinAPI.GetClassName(hWnd, className, className.Capacity);

            //Console.WriteLine(string.Format("{0} {1} {2}", hWnd.ToString("x8"), className, windowName));

            if (className.ToString() != "Button")
            {
                return(false);
            }

            uint processid = 0;

            WinAPI.GetWindowThreadProcessId(hWnd, out processid);
            if (windowName.ToString().Replace("&", "") == name)
            {
                return(true);
            }

            return(false);
        }
示例#4
0
        internal void WaitChildWindowThen(params object[] args)
        {
            Dictionary <string, Action <Window> > dict = new Dictionary <string, Action <Window> >();

            for (int i = 0; i < args.Length; i += 2)
            {
                string          key    = args[i] as string;
                Action <Window> action = args[i + 1] as Action <Window>;
                dict.Add(key, action);
            }

            int iCount = 0;

            while (iCount < 1000)
            {
                Window findWindow = null;

                WinAPI.EnumChildWindows(_hWnd, new WinAPI.EnumWindowsProc((hWnd, lParam) =>
                {
                    int length = WinAPI.GetWindowTextLength(hWnd);
                    StringBuilder windowName = new StringBuilder(length + 1);
                    WinAPI.GetWindowText(hWnd, windowName, windowName.Capacity);

                    string fid = null;
                    foreach (var elem in dict)
                    {
                        if (windowName.ToString().Replace("&", "").Contains(elem.Key))
                        {
                            fid = elem.Key;
                            break;
                        }
                    }

                    if (fid == null)
                    {
                        return(true);
                    }

                    findWindow = (Window)Activator.CreateInstance(typeof(Window), hWnd, fid);
                    return(false);
                }),
                                        0);

                if (findWindow != null)
                {
                    Log.INFO(string.Format("Finded Window:[{0},{1}]", findWindow._name, findWindow._hWnd.ToString("X8")));

                    dict[findWindow._name](findWindow);
                    return;
                }

                iCount++;

                Thread.Sleep(200);
            }

            throw new ArgumentException(string.Format("can not find windows:[{0}]", String.Join(",", dict.Keys)));
        }
示例#5
0
        public static string GetWindowText(IntPtr hwnd)
        {
            int           length     = WinAPI.GetWindowTextLength(hwnd);
            StringBuilder windowName = new StringBuilder(length + 1);

            WinAPI.GetWindowText(hwnd, windowName, windowName.Capacity);

            return(windowName.ToString());
        }
示例#6
0
        //public Window FindWindowContains(string winText)
        //{
        //    try
        //    {

        //        Window findWindow = null;

        //        WaitUntil((String findName) =>
        //        {
        //            WinAPI.EnumWindows(new WinAPI.EnumWindowsProc((hWnd, lParam) =>
        //            {
        //                uint pid = 0;
        //                WinAPI.GetWindowThreadProcessId(hWnd, out pid);

        //                if (pid != _process.Id)
        //                {
        //                    return true;
        //                }

        //                int length = WinAPI.GetWindowTextLength(hWnd);
        //                StringBuilder windowName = new StringBuilder(length + 1);
        //                WinAPI.GetWindowText(hWnd, windowName, windowName.Capacity);

        //                if (windowName.ToString().Replace("&", "").Contains(findName))
        //                {
        //                    findWindow = (Window)Activator.CreateInstance(typeof(Window), hWnd, findName);
        //                    return false;
        //                }

        //                return true;
        //            }),
        //                            (IntPtr)0);

        //            if (findWindow != null)
        //            {
        //                return true;
        //            }

        //            return false;
        //        },
        //                   winText,
        //                   60);

        //        Log.INFO(string.Format("Finded Winow:[{0},{1}], in PID:[{2}]", winText, findWindow.hwnd.ToString("X8"), _process.Id.ToString("X8")));
        //        return findWindow;
        //    }
        //    catch (Exception e)
        //    {
        //        throw new ArgumentException(string.Format("can not find window:[{0}] in PID:[{1}]", winText, _process.Id.ToString("X8")));
        //    }
        //}

        public Window TryFindWindow(string winText)
        {
            try
            {
                Window findWindow = null;

                WaitUntil((String findName) =>
                {
                    WinAPI.EnumWindows(new WinAPI.EnumWindowsProc((hWnd, lParam) =>
                    {
                        uint pid = 0;
                        WinAPI.GetWindowThreadProcessId(hWnd, out pid);

                        if (pid != _process.Id)
                        {
                            return(true);
                        }

                        int length = WinAPI.GetWindowTextLength(hWnd);
                        StringBuilder windowName = new StringBuilder(length + 1);
                        WinAPI.GetWindowText(hWnd, windowName, windowName.Capacity);

                        if (windowName.ToString().Replace("&", "") == findName)
                        {
                            findWindow = (Window)Activator.CreateInstance(typeof(Window), hWnd, findName);
                            return(false);
                        }

                        return(true);
                    }),
                                       (IntPtr)0);

                    if (findWindow != null)
                    {
                        return(true);
                    }

                    return(false);
                },
                          winText,
                          5);

                Log.INFO(string.Format("Finded Winow:[{0},{1}], in PID:[{2}]", winText, findWindow.hwnd.ToString("X8"), _process.Id.ToString("X8")));
                return(findWindow);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
示例#7
0
        public string GetValue()
        {
            int length = WinAPI.GetWindowTextLength(_hWnd);

            StringBuilder TextName = new StringBuilder(length + 1000);

            WinAPI.GetWindowText(_hWnd, TextName, TextName.Capacity);

            string text = TextName.ToString();

            Log.INFO(string.Format("Get StaticText:[{0}, {1}] value:[{2}] Win:[{3}]", _hWnd.ToString("X8"), _Text, text, _hWndWin.ToString("X8")));

            return(text);
        }
示例#8
0
        public static ToolbarButton CreateByIndex(IntPtr hWnd, IntPtr hWndWin, int indexBaseZero, ref int currIndex)
        {
            int           length    = WinAPI.GetWindowTextLength(hWnd);
            StringBuilder className = new StringBuilder(length + 1000);

            WinAPI.GetClassName(hWnd, className, className.Capacity);

            uint processid = 0;

            WinAPI.GetWindowThreadProcessId(hWnd, out processid);

            if (className.ToString() != "ToolbarWindow32")
            {
                return(null);
            }

            WinAPI.TBBUTTON tb = new WinAPI.TBBUTTON();
            WinAPI.GetToolbarButton(hWnd, indexBaseZero, ref tb);

            return((ToolbarButton)Activator.CreateInstance(typeof(ToolbarButton), hWnd, hWndWin, string.Format("ToolbarButton[{0}]", indexBaseZero), tb.idCommand));
        }
示例#9
0
            public IntPtr Find(string name)
            {
                int           length     = WinAPI.GetWindowTextLength(hWnd);
                StringBuilder windowName = new StringBuilder(length + 1);

                WinAPI.GetWindowText(this.hWnd, windowName, windowName.Capacity);

                if (windowName.ToString() == name)
                {
                    return(this.hWnd);
                }

                foreach (WinTree tree in subWin)
                {
                    IntPtr find = tree.Find(name);
                    if (find != IntPtr.Zero)
                    {
                        return(find);
                    }
                }

                return(IntPtr.Zero);
            }