コード例 #1
0
ファイル: Window.cs プロジェクト: Uranus359/WRing
        // alt constructors etc

        public static Window[] GetAllWindows()
        {
            List <Window> wins = new List <Window>();
            var           a    = new WinAPI.EnumWindowsCB(cb);

            WinAPI.EnumWindows(a, 0);
            bool cb(IntPtr hwnd, int lp)
            {
                wins.Add(Find(hwnd));
                return(true);
            }

            return(wins.ToArray());
        }
コード例 #2
0
ファイル: Window.cs プロジェクト: Uranus359/WRing
        public static Window[] GetWindowsByText(TextSearchConditional cond, string arg = "")
        {
            List <Window> wins = new List <Window>();
            var           a    = new WinAPI.EnumWindowsCB(cb);

            WinAPI.EnumWindows(a, 0);
            bool cb(IntPtr hwnd, int lp)
            {
                wins.Add(Find(hwnd));
                return(true);
            }

            switch (cond)
            {
            case TextSearchConditional.WithText:
                wins = wins.FindAll((w) => w.GetText().Length > 0);
                break;

            case TextSearchConditional.NoText:
                wins = wins.FindAll((w) => w.GetText().Length == 0);
                break;

            case TextSearchConditional.Equal:
                wins = wins.FindAll((w) => w.GetText() == arg);
                break;

            case TextSearchConditional.EqualIgnoreCase:
                wins = wins.FindAll((w) => w.GetText().ToLower() == arg.ToLower());
                break;

            case TextSearchConditional.Contains:
                wins = wins.FindAll((w) => w.GetText().Contains(arg));
                break;

            case TextSearchConditional.StartsWith:
                wins = wins.FindAll((w) => w.GetText().StartsWith(arg));
                break;

            case TextSearchConditional.EndsWith:
                wins = wins.FindAll((w) => w.GetText().EndsWith(arg));
                break;

            default:
                throw new Exception(((int)cond).ToString());
            }
            return(wins.ToArray());
        }