Beispiel #1
0
        internal static bool IsAltTabWindow(IntPtr windowHandle)
        {
            if (!WindowsFunctions.IsWindowVisible(windowHandle))
            {
                return(false);
            }

            const int GA_ROOTOWNER = 3;
            var       hwndTry      = WindowsFunctions.GetAncestor(windowHandle, GA_ROOTOWNER);

            var hwndWalk = IntPtr.Zero;

            while (hwndTry != hwndWalk)
            {
                hwndWalk = hwndTry;
                hwndTry  = WindowsFunctions.GetLastActivePopup(hwndWalk);
                if (WindowsFunctions.IsWindowVisible(hwndTry))
                {
                    break;
                }
            }

            if (hwndWalk != windowHandle)
            {
                return(false);
            }

            // the following removes some task tray programs and "Program Manager"
            var titleBarInfo = new WindowsFunctions.TITLEBARINFO();

            titleBarInfo.cbSize = Marshal.SizeOf(titleBarInfo);
            WindowsFunctions.GetTitleBarInfo(windowHandle, ref titleBarInfo);

            const int STATE_SYSTEM_INVISIBLE = 0x00008000;

            if ((titleBarInfo.rgstate[0] & STATE_SYSTEM_INVISIBLE) != 0)
            {
                return(false);
            }


            // Tool windows should not be displayed either, these do not appear in the
            // task bar.
            const int  GWL_EXSTYLE      = -20;
            const long WS_EX_TOOLWINDOW = 0x00000080L;

            if ((WindowsFunctions.GetWindowLong(windowHandle, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) != 0)
            {
                return(false);
            }

            WindowsFunctions.DwmGetWindowAttribute(windowHandle,
                                                   WindowsFunctions.DWMWINDOWATTRIBUTE.Cloaked,
                                                   out var isCloaked,
                                                   Marshal.SizeOf(typeof(bool)));

            if (isCloaked)
            {
                return(false);
            }

            return(true);
        }