Example #1
0
        /// <summary>
        /// 窗口是否是最大化
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        public static bool IsMAXIMIZED(IntPtr handle, bool onlyFullScreen)
        {
            WINDOWPLACEMENT placment = new WINDOWPLACEMENT();

            User32Wrapper.GetWindowPlacement(handle, ref placment);
            //_ = User32WrapperEx.GetProcessId(handle);

            bool visible = User32Wrapper.IsWindowVisible(handle);

            if (visible)
            {
                if (!onlyFullScreen && placment.showCmd == WINDOWPLACEMENTFlags.SW_SHOWMAXIMIZED)
                {//窗口最大化
                 // Exclude suspended Windows apps
                    _ = DwmapiWrapper.DwmGetWindowAttribute(handle, DwmapiWrapper.DWMWINDOWATTRIBUTE.DWMWA_CLOAKED, out var cloaked, Marshal.SizeOf <bool>());
                    //隐藏的UWP窗口
                    if (cloaked)
                    {
                        return(false);
                    }
                    //System.Diagnostics.Debug.WriteLine($"pid:{pid} maximized");
                    return(true);
                }

                ////判断一些隐藏窗口
                ////http://forums.codeguru.com/showthread.php?445207-Getting-HWND-of-visible-windows
                //var wl = User32Wrapper.GetWindowLong(handle, WindowLongConstants.GWL_STYLE) & WindowStyles.WS_EX_APPWINDOW;
                //if (wl <= 0)
                //    return false;

                //判断是否是游戏全屏
                User32Wrapper.GetWindowRect(handle, out var r);

                //System.Diagnostics.Debug.WriteLine($"pid:{pid} r:{r.Left} {r.Top} {r.Right} {r.Bottom} {DateTime.Now}");
                if (r.Left == 0 && r.Top == 0)
                {
                    int with   = r.Right - r.Left;
                    int height = r.Bottom - r.Top;

                    if (height == Screen.PrimaryScreen.Bounds.Height &&
                        with == Screen.PrimaryScreen.Bounds.Width)
                    {
                        //当前窗口最大化,进入了游戏
                        var foregroundWIndow = User32Wrapper.GetForegroundWindow();
                        if (foregroundWIndow == handle)
                        {
                            _ = User32WrapperEx.GetWindowTextEx(handle);
                            //var desktop = User32Wrapper.GetDesktopWindow();
                            var className = User32Wrapper.GetClassName(handle);
                            if (className == "WorkerW")
                            {
                                return(false);
                            }
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        private static string GetActiveWindowTitle()
        {
            const int     nChars = 256;
            StringBuilder Buff   = new StringBuilder(nChars);
            IntPtr        handle = User32Wrapper.GetForegroundWindow();

            if (User32Wrapper.GetWindowText(handle, Buff, nChars) > 0)
            {
                return($"handle:{handle} buff:{Buff}");
            }
            return($"handle:{handle}");
        }
        private string GetActiveWindowTitle()
        {
            const int     nChars = 256;
            StringBuilder Buff   = new StringBuilder(nChars);
            IntPtr        handle = User32Wrapper.GetForegroundWindow();

            if (User32Wrapper.GetWindowText(handle, Buff, nChars) > 0)
            {
                return(Buff.ToString());
            }
            return(null);
        }
        internal static bool IsDesktop()
        {
            IntPtr hWnd = User32Wrapper.GetForegroundWindow();

            if (hWnd == _desktopWorkerw)
            {
                return(true);
            }
            else if (hWnd == _progman)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }