Ejemplo n.º 1
0
        private static bool Filter(int hwnd, int lparam, out ApplicationWindow window)
        {
            window = null;
            var iHwnd = new IntPtr(hwnd);


            var title = new StringBuilder(256);

            User32.GetWindowText(hwnd, title, 256);
            var t = title.ToString();

            //Skip if the window does not have a caption.
            if (t.Length == 0)
            {
                return(true);
            }

            //Skip if parent is not the desktop.
            var parentHwnd = User32.GetParent(iHwnd);

            if (!parentHwnd.Equals(new IntPtr(0)))
            {
                return(true);
            }

            if (!User32.KeepWindowHandleInAltTabList(iHwnd))
            {
                return(true);
            }

            //Skip if the window is not visible but not minimized and has SW_HIDE (0) style.
            var placement = new WINDOWPLACEMENT();

            User32.GetWindowPlacement(iHwnd, ref placement);
            if (!User32.IsWindowVisible(hwnd) && !User32.IsIconic(iHwnd) && placement.flags == 0)
            {
                return(true);
            }

            var info = new WINDOWINFO();

            info.cbSize = (uint)Marshal.SizeOf(info);
            User32.GetWindowInfo(iHwnd, ref info);
            //skip window if it's really small (usually an indicator it's not a alt tab candidate window.
            if (info.rcWindow.Width <= 10 && info.rcWindow.Height <= 10)
            {
                return(true);
            }

            window = ApplicationWindows.GetApplicationWindow(hwnd, lparam);

            return(true);
        }
Ejemplo n.º 2
0
        public static ApplicationWindow FindWindowByCaption(string caption)
        {
            ApplicationWindow window = null;
            var ewp = new User32.EnumWindowsProc((hwnd, lparam) =>
            {
                var w = ApplicationWindows.GetApplicationWindow(hwnd, lparam);
                if (w != null && w.Title.Equals(caption, StringComparison.InvariantCulture))
                {
                    window = w;
                }

                return(window == null);                  //continue as long as window == null;
            });

            User32.EnumWindows(ewp, 0);
            return(window);
        }
Ejemplo n.º 3
0
        private static IEnumerable <ApplicationWindow> FindAltTabableWindows()
        {
            var windows = new List <ApplicationWindow>();
            var ewp     = new User32.EnumWindowsProc((hwnd, lparam) =>
            {
                ApplicationWindow window = null;
                var shouldContinue       = ApplicationWindows.Filter(hwnd, lparam, out window);
                if (window != null)
                {
                    windows.Add(window);
                }
                return(shouldContinue);
            });

            User32.EnumWindows(ewp, 0);
            return(windows.DistinctBy(w => w.hWnd));
        }