Example #1
0
        public static void SendWindowToBackground(string windowTitleStartsWith)
        {
            var foundWindows = AppWindowEx.GetWindows();

            var foundLegacyWindows = foundWindows.Where(x => x.Title.StartsWith(windowTitleStartsWith, StringComparison.InvariantCultureIgnoreCase));

            if (foundLegacyWindows.Count() == 1)
            {
                AppWindowEx.SetWindowBottomMost(foundLegacyWindows.First().Handle);
            }
        }
Example #2
0
        public static List <AppWindowEx> GetWindows()
        {
            List <AppWindowEx> windows = new List <AppWindowEx>();

            User32.EnumWindows(
                delegate(IntPtr hWnd, IntPtr lParam)
            {
                if (!User32.IsWindowVisible(hWnd))
                {
                    return(true);
                }

                int length = User32.GetWindowTextLength(hWnd);
                if (length == 0)
                {
                    return(true);
                }

                WindowInfo windowInfo = new WindowInfo();
                bool success          = User32.GetWindowInfo(hWnd, ref windowInfo);
                if (success)
                {
                    AppWindowEx appWindow = new AppWindowEx();
                    appWindow.Handle      = hWnd;
                    appWindow.WindowInfo  = windowInfo;

                    if (length == 0)
                    {
                        return(true);
                    }
                    StringBuilder builder = new StringBuilder(length);
                    User32.GetWindowText(hWnd, builder, length + 1);
                    appWindow.Title = builder.ToString();

                    windows.Add(appWindow);
                }

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