예제 #1
0
        private static void ResetGUIInfo(GUIInfoType guiInfoType, int hwnd, ref int hWndTarget,
                                         ref string windowText, ref string className, ref string parentText,
                                         StringBuilder sWindowText, StringBuilder sClassname, StringBuilder sParentText)
        {
            string clsStartedWith = "";

            if (className.IndexOf(".") >= 0)
            {
                clsStartedWith = className.Replace(className.Split('.')[className.Split('.').Length - 1], "");
            }
            else
            {
                clsStartedWith = className;
            }

            if (guiInfoType == GUIInfoType.guiText)
            {
                if (sWindowText.ToString() == windowText)
                {
                    hWndTarget = hwnd;
                    className  = sClassname.ToString();
                    parentText = sParentText.ToString();
                }
            }
            else if (guiInfoType == GUIInfoType.guiTextClass)
            {
                if (sWindowText.ToString() == windowText && sClassname.ToString().StartsWith(clsStartedWith))
                {
                    hWndTarget = hwnd;
                    parentText = sParentText.ToString();
                }
            }
            else if (guiInfoType == GUIInfoType.guiTextParent)
            {
                if (sWindowText.ToString() == windowText && sParentText.ToString() == parentText)
                {
                    hWndTarget = hwnd;
                    className  = sClassname.ToString();
                }
            }
            else if (guiInfoType == GUIInfoType.guiTextClassParent)
            {
                if (sWindowText.ToString() == windowText && sClassname.ToString().StartsWith(clsStartedWith) && sParentText.ToString() == parentText)
                {
                    hWndTarget = hwnd;
                }
            }
            else if (guiInfoType == GUIInfoType.guiClassParent)
            {
                //				if (sClassname.ToString().StartsWith("WindowsForms10.LISTBOX."))
                //				{
                //					string xxx="";
                //				}
                if (sClassname.ToString().StartsWith(clsStartedWith) && sParentText.ToString() == parentText)
                {
                    hWndTarget = hwnd;
                    windowText = sWindowText.ToString();
                }
            }
        }
예제 #2
0
        private static int maxLen = 10000;         //need to modify text chapter 4
        public static int FindGUILike(ref int hWndTarget, int hWndStart,
                                      ref string windowText, ref string className, ref string parentText)
        {
            int hwnd = 0;
            int r    = 0;
            //int level = 0;
            StringBuilder sWindowText = new StringBuilder();
            StringBuilder sClassname  = new StringBuilder();
            StringBuilder sParentText = new StringBuilder();

            if (level == 0)
            {
                hWndTarget = 0;
                if (hWndStart == 0)
                {
                    hWndStart = GetDesktopWindow();
                }
            }
            level = level + 1;

            hwnd = GetWindow(hWndStart, GW_CHILD);


            while (hwnd != 0)
            {
                r = FindGUILike(ref hWndTarget, hwnd, ref windowText, ref className, ref parentText);

                sWindowText.Capacity = maxLen;                 //need to modify text chapter 4
                r = GetWindowText(hwnd, sWindowText, maxLen);
                sClassname.Capacity = maxLen;
                r = GetClassName(hwnd, sClassname, maxLen);
                sParentText.Capacity = maxLen;
                r = GetWindowText(GetParent(hwnd), sParentText, maxLen);

                GUIInfoType guiInfoType = GetGUIInfoType(windowText, className, parentText);

                ResetGUIInfo(guiInfoType, hwnd, ref hWndTarget, ref windowText, ref className, ref parentText, sWindowText, sClassname, sParentText);
                // Get next child window:
                hwnd = GetWindow(hwnd, GW_HWNDNEXT);
            }
            //  Decrement recursion counter:
            level = level - 1;
            return(0);
        }