Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public bool SendToBackground(IntPtr handler, int displayIndex = 0)
        {
            if (handler == IntPtr.Zero || Shown)
            {
                return(false);
            }

            var ok = User32Wrapper.GetWindowRect(handler, out RECT react);

            if (ok)
            {
                _originalRect = react;
            }

            Shown         = true;
            _targeHandler = handler;

            if (_workerw == IntPtr.Zero)
            {
                _workerw = GetWorkerW();
            }

            _parentHandler = User32Wrapper.GetParent(_targeHandler);
            if (_parentHandler == IntPtr.Zero)
            {
                _parentHandler = User32Wrapper.GetAncestor(_targeHandler, GetAncestorFlags.GetParent);
            }

            User32Wrapper.SetParent(_targeHandler, _workerw);

            FullScreen(_targeHandler, displayIndex);

            return(true);
        }
Ejemplo n.º 3
0
        public bool SendToBackground(IntPtr handler)
        {
            //处理alt+tab可以看见本程序
            //https://stackoverflow.com/questions/357076/best-way-to-hide-a-window-from-the-alt-tab-program-switcher
            int exStyle = User32Wrapper.GetWindowLong(handler, WindowLongFlags.GWL_EXSTYLE);

            exStyle |= (int)WindowStyles.WS_EX_TOOLWINDOW;
            User32Wrapper.SetWindowLong(handler, WindowLongFlags.GWL_EXSTYLE, exStyle);

            if (handler != _currentHandler)
            {
                //已经换了窗口,恢复上一个窗口
                RestoreParent();
            }

            if (handler == IntPtr.Zero)
            {
                return(false);
            }

            _ = User32Wrapper.GetWindowRect(handler, out _);
            //var ok = User32Wrapper.GetWindowRect(handler, out RECT react);
            //if (ok)
            //    _originalRect = react;

            _currentHandler = handler;

            var workerw = GetWorkerW();

            if (workerw == IntPtr.Zero)
            {
                //有时候突然又不行了,在来一次
                User32Wrapper.SystemParametersInfo(User32Wrapper.SPI_SETCLIENTAREAANIMATION, 0, true, User32Wrapper.SPIF_UPDATEINIFILE | User32Wrapper.SPIF_SENDWININICHANGE);
                workerw = GetWorkerW();
            }

            if (workerw == IntPtr.Zero)
            {
                return(false);
            }

            _parentHandler = User32Wrapper.GetParent(_currentHandler);

            //if (newParentHandler != _parentHandler)
            //{
            //    //parent没变时不重复调用,有时候会导致不可见
            User32Wrapper.SetParent(_currentHandler, workerw);
            FullScreen(_currentHandler, _targetBounds, workerw);
            //_parentHandler = newParentHandler;
            //}

            //if (_parentHandler == IntPtr.Zero)
            //    _parentHandler = User32Wrapper.GetAncestor(_currentHandler, GetAncestorFlags.GetParent);

            return(true);
        }
Ejemplo n.º 4
0
        public bool SendToBackground(IntPtr handler)
        {
            if (handler != _currentHandler)
            {
                //已经换了窗口,恢复上一个窗口
                RestoreParent();
            }

            if (handler == IntPtr.Zero)
            {
                return(false);
            }

            var ok = User32Wrapper.GetWindowRect(handler, out RECT react);

            if (ok)
            {
                _originalRect = react;
            }

            _currentHandler = handler;

            var workerw = GetWorkerW();

            if (workerw == IntPtr.Zero)
            {
                //有时候突然又不行了,在来一次
                User32Wrapper.SystemParametersInfo(User32Wrapper.SPI_SETCLIENTAREAANIMATION, 0, true, User32Wrapper.SPIF_UPDATEINIFILE | User32Wrapper.SPIF_SENDWININICHANGE);
                workerw = GetWorkerW();
            }

            if (workerw == IntPtr.Zero)
            {
                return(false);
            }

            _parentHandler = User32Wrapper.GetParent(_currentHandler);
            FullScreen(_currentHandler, _targetBounds);
            User32Wrapper.SetParent(_currentHandler, workerw);

            //if (_parentHandler == IntPtr.Zero)
            //    _parentHandler = User32Wrapper.GetAncestor(_currentHandler, GetAncestorFlags.GetParent);

            return(true);
        }
        public bool SendToBackground(IntPtr handler)
        {
            if (Shown && handler != _currentHandler)
            {
                //已经换了窗口,恢复上一个窗口
                RestoreParent(false);
            }

            if (handler == IntPtr.Zero || Shown)
            {
                return(false);
            }

            var ok = User32Wrapper.GetWindowRect(handler, out RECT react);

            if (ok)
            {
                _originalRect = react;
            }

            Shown           = true;
            _currentHandler = handler;

            if (_workerw == IntPtr.Zero)
            {
                _workerw = GetWorkerW();
                if (_workerw == IntPtr.Zero)
                {
                    return(false);
                }
            }

            _parentHandler = User32Wrapper.GetParent(_currentHandler);
            if (_parentHandler == IntPtr.Zero)
            {
                _parentHandler = User32Wrapper.GetAncestor(_currentHandler, GetAncestorFlags.GetParent);
            }

            User32Wrapper.SetParent(_currentHandler, _workerw);

            FullScreen(_currentHandler, DisplayScreen);

            return(true);
        }
        private void BtnGetOpenedWindows_OnClick(object sender, RoutedEventArgs e)
        {
            _monitorCheckTimer.Elapsed += OnMonitorCheck;
            _monitorCheckTimer.Start();

            //return;
            WinPosition.GetMonitorCount();
            foreach (KeyValuePair <IntPtr, string> window in _winPosition.GetOpenWindows())
            {
                IntPtr handle = window.Key;
                string title  = window.Value;

                var windowRect = new Rectangle();
                User32Wrapper.GetWindowRect(handle, ref windowRect);

                lstBox.Items.Add($"{handle}: {title} : {windowRect}");
                if (title.Contains("iTunes"))
                {
                    User32Wrapper.SetWindowPos(handle, (IntPtr)SpecialWindowHandles.HWND_TOP, windowRect.Left + 1000,
                                               windowRect.Top + 100, windowRect.Right - windowRect.Left, windowRect.Bottom - windowRect.Top,
                                               SetWindowPosFlags.ShowWindow);
                }
            }
        }
Ejemplo n.º 7
0
 internal static void FullScreen(IntPtr mainWindowHandle, IntPtr containerHandle)
 {
     User32Wrapper.GetWindowRect(containerHandle, out RECT rect);
     FullScreen(mainWindowHandle, rect, containerHandle);
 }