示例#1
0
        // Private helper methods
        private static int FindControlStart(int hWnd, string className, string controlText)
        {
            int hWndFound = 0;

            CallBack callBack = delegate(int hWndToCheck, int lParam) {
                StringBuilder sb = new StringBuilder(512);

                WinApi.GetWindowText(hWndToCheck, sb, 512);
                string windowText = sb.ToString().Trim();

                WinApi.GetClassName(hWndToCheck, sb, 512);
                string classText = sb.ToString().Trim();

                if (classText.Equals(className))
                {
                    if (windowText.Replace("&", "").ToLower().StartsWith(controlText.ToLower()))
                    {
                        hWndFound = hWndToCheck;
                        return(0);
                    }
                }
                return(1);
            };

            WinApi.EnumChildWindows(hWnd, callBack, 0);

            return(hWndFound);
        }
示例#2
0
        private static int FindWindowAny(string className, string windowName)
        {
            int hWndFound = 0;

            CallBack callBack = delegate(int hWnd, int lParam) {
                StringBuilder sb = new StringBuilder(512);

                WinApi.GetWindowText(hWnd, sb, 512);
                string windowText = sb.ToString().Trim();

                WinApi.GetClassName(hWnd, sb, 512);
                string classText = sb.ToString().Trim();

                if (classText.Equals(className))
                {
                    if (windowText.Contains(windowName))
                    {
                        hWndFound = hWnd;
                        return(0);
                    }
                }
                return(1);
            };

            WinApi.EnumWindows(callBack, 0);

            return(hWndFound);
        }
示例#3
0
        public static int ControlGetHandle(int hWnd, string className, int instance)
        {
            int hWndFound     = 0;
            int instanceCount = 0;

            CallBack callBack = delegate(int hWndToCheck, int lParam) {
                StringBuilder sb = new StringBuilder(512);

                WinApi.GetWindowText(hWndToCheck, sb, 512);
                string windowText = sb.ToString().Trim();

                WinApi.GetClassName(hWndToCheck, sb, 512);
                string classText = sb.ToString().Trim();

                if (classText.Equals(className))
                {
                    instanceCount++;

                    if (instanceCount == instance)
                    {
                        hWndFound = hWndToCheck;
                        return(0);
                    }
                }
                return(1);
            };

            WinApi.EnumChildWindows(hWnd, callBack, 0);

            return(hWndFound);
        }