コード例 #1
0
        private static Result MatchWindowText(WindowFinderEnumWindowsProcContextBase context, IntPtr windowHandle)
        {
            var windowText = new StringBuilder(1024);

            context.NativeMethods.GetWindowText(windowHandle, windowText, windowText.Capacity);
            // ignores return value (length). Window text with length 0 can be either a window with an empty window text or an error.

            var result = new Result
            {
                Value   = windowText.ToString(),
                IsMatch = context.WindowTextConstraint == null || context.WindowTextConstraint.IsMatch(windowText.ToString())
            };

            return(result);
        }
コード例 #2
0
        private static Result MatchClassName(WindowFinderEnumWindowsProcContextBase context, IntPtr windowHandle)
        {
            var className = new StringBuilder(256);

            var length = context.NativeMethods.GetClassName(windowHandle, className, className.Capacity);

            if (length == 0)
            {
                // Marshal.GetLastWin32Error could be used to retrieve the detailed error information but since the error is not logged, there's no need.
                return(null);
            }

            var result = new Result
            {
                Value   = className.ToString(),
                IsMatch = context.ClassNameConstraint == null || context.ClassNameConstraint.IsMatch(className.ToString())
            };

            return(result);
        }