Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="window"></param>
        /// <returns></returns>
        public static bool KeepWindowHandleInAltTabList(IntPtr window)
        {
            if (window == GetShellWindow() || GetWindowTextLength(window) == 0)   //Desktop or without title
            {
                return(false);
            }

            //uint processId = 0;
            //Interop.GetWindowThreadProcessId(window, out processId);
            //System.Diagnostics.Process process = System.Diagnostics.Process.GetProcessById((int)processId);
            //if (process.MainModule.FileName.EndsWith("ShellExperienceHost.exe"))
            //    return false;

            //http://stackoverflow.com/questions/210504/enumerate-windows-like-alt-tab-does
            //http://blogs.msdn.com/oldnewthing/archive/2007/10/08/5351207.aspx
            //1. For each visible window, walk up its owner chain until you find the root owner.
            //2. Then walk back down the visible last active popup chain until you find a visible window.
            //3. If you're back to where you're started, (look for exceptions) then put the window in the Alt+Tab list.
            IntPtr root = GetAncestor(window, GaFlags.GA_ROOTOWNER);

            if (GetLastVisibleActivePopUpOfWindow(root) == window)
            {
                Me.Catx.Native.WindowInfo wi = new Me.Catx.Native.WindowInfo(window);

                if (wi.ClassName == "Shell_TrayWnd" ||                         //Windows taskbar
                    wi.ClassName == "DV2ControlHost" ||                        //Windows startmenu, if open
                    (wi.ClassName == "Button" && wi.WindowText == "Start") ||  //Windows startmenu-button.
                    wi.ClassName == "MsgrIMEWindowClass" ||                    //Live messenger's notifybox i think
                    wi.ClassName == "SysShadow" ||                             //Live messenger's shadow-hack
                    wi.ClassName.StartsWith("WMP9MediaBarFlyout"))             //WMP's "now playing" taskbar-toolbar
                {
                    return(false);
                }

                return(true);
            }
            return(false);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="window"></param>
        /// <returns></returns>
        public static bool KeepWindowHandleInAltTabList(IntPtr window)
        {
            if (window == WinApi.GetShellWindow() || WinApi.GetWindowTextLength(window) == 0)   //Desktop or without title
                return false;

            if (!IsWindowThreadAlive(window))
                return false;

            //http://stackoverflow.com/questions/210504/enumerate-windows-like-alt-tab-does
            //http://blogs.msdn.com/oldnewthing/archive/2007/10/08/5351207.aspx
            //1. For each visible window, walk up its owner chain until you find the root owner.
            //2. Then walk back down the visible last active popup chain until you find a visible window.
            //3. If you're back to where you're started, (look for exceptions) then put the window in the Alt+Tab list.
            IntPtr root = WinApi.GetAncestor(window, WinApi.GaFlags.GA_ROOTOWNER);
            if (GetLastVisibleActivePopUpOfWindow(root) == window)
            {
                var wi = new Me.Catx.Native.WindowInfo(window);
                if (wi.ClassName == "Shell_TrayWnd" ||                          //Windows taskbar
                    wi.ClassName == "DV2ControlHost" ||                         //Windows startmenu, if open
                    (wi.ClassName == "Button" && wi.WindowText == "Start") ||   //Windows startmenu-button.
                    wi.ClassName == "MsgrIMEWindowClass" ||                     //Live messenger's notifybox i think
                    wi.ClassName == "SysShadow" ||                              //Live messenger's shadow-hack
                    wi.ClassName.StartsWith("WMP9MediaBarFlyout") ||            //WMP's "now playing" taskbar-toolbar
                    wi.ClassName == "ApplicationFrameWindow")                   //win10 applications like calendar, xbox frame and other
                    return false;
                return true;
            }
            return false;
        }