Exemple #1
0
        private static IntPtr FindDescendantBy(IntPtr parent, string className = null, string text = null)
        {
            var matches = new List <IntPtr>();

            WindowsApi.EnumChildWindows(parent, (handle, pointer) =>
            {
                if (
                    (className == null || WindowsHelpers.GetWindowClassName(handle) == className)
                    &&
                    (text == null || WindowsHelpers.GetWindowTextRaw(handle) == text)
                    )
                {
                    matches.Add(handle);
                }

                return(true);
            }, IntPtr.Zero);

            if (matches.Count > 1)
            {
                throw new Exception($"Found {matches.Count} matching descendants.");
            }

            return(matches.FirstOrDefault());
        }
        private static List <IntPtr> FindDescendantsBy(IntPtr parent, string className = null, string text = null)
        {
            var matches = new List <IntPtr>();

            WindowsApi.EnumChildWindows(parent, (handle, pointer) =>
            {
                if (
                    (className == null || WindowsHelpers.GetWindowClassName(handle) == className)
                    &&
                    (text == null || WindowsHelpers.GetWindowTextRaw(handle) == text)
                    )
                {
                    matches.Add(handle);
                }

                return(true);
            }, IntPtr.Zero);

            return(matches);
        }