Beispiel #1
0
        /// <summary>
        /// Change window style (switch between borderless and default style)
        /// </summary>
        /// <param name="hWndGame">Window hWnd to handle</param>
        public static void ChangeBorderStyle(IntPtr hWndGame, Process ProcessGame = null)
        {
            Settings.HandlingMode mode = (ProcessGame == null) ? Settings.HandlingMode.MANUAL : Settings.HandlingMode.AUTO;

            try
            {
                int actStyle = WindowLib.GetWindowLong(hWndGame, WindowLib.GWL_STYLE);

                if (actStyle == 0)
                {
                    Settings.WriteInLogs(Settings.ErrorCategory.WARNING, mode, $"Can't get window style of '{WindowLib.GetProcessName(hWndGame)}'! Trying again...");
                    if (ProcessGame != null)
                    {
                        _IsSuccessful = false;
                    }
                    return;
                }

                if (ProcessGame != null)
                {
                    if (!ProcessGame.Responding)
                    {
                        Settings.WriteInLogs(Settings.ErrorCategory.WARNING, mode, $"Process '{WindowLib.GetProcessName(hWndGame)}' not responding! Trying again...");
                        _IsSuccessful = false;
                        return;
                    }

                    // MainWindow.ExcludedProcesses.Add(ProcessGame.Id);
                    _ExcludedhWnd.Add(hWndGame);
                }

                if (_hWndList.Any(i => i.id == hWndGame))
                {
                    // Get process info
                    hWndInfos hWndInfo = _hWndList.Find(i => i.id == hWndGame);

                    // Restablishing window style
                    WindowLib.SetWindowLong(hWndGame, WindowLib.GWL_STYLE, hWndInfo.Style);

                    // Restablishing window dimension and location
                    WindowLib.MoveWindow(hWndGame, hWndInfo.LocationX, hWndInfo.LocationY, hWndInfo.Width, hWndInfo.Height, true);

                    // Deleting process info (to refresh them when called again)
                    _hWndList.Remove(hWndInfo);

                    // Write info to logs
                    Settings.WriteInLogs(Settings.ErrorCategory.INFO, mode, $"Successfully restored old style of '{WindowLib.GetProcessName(hWndGame)}'!");
                }
                else
                {
                    // Add process infos
                    WindowLib.RECT rect = new WindowLib.RECT();
                    WindowLib.GetWindowRect(hWndGame, ref rect);
                    hWndInfos hWndInfo = new hWndInfos(hWndGame, actStyle, rect.Left, rect.Top, rect.Right - rect.Left + 1, rect.Bottom - rect.Top + 1);
                    _hWndList.Add(hWndInfo);

                    // Deleting title bar
                    WindowLib.SetWindowLong(hWndGame, WindowLib.GWL_STYLE, (actStyle & ~WindowLib.WS_CAPTION & ~WindowLib.WS_THICKFRAME & ~WindowLib.WS_SYSMENU & ~WindowLib.WS_MINIMIZE & ~WindowLib.WS_MAXIMIZEBOX));

                    // Changing window dimension and location
                    WindowLib.MoveWindow(hWndGame, 0, 0, (int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, true);

                    // Write info to logs
                    Settings.WriteInLogs(Settings.ErrorCategory.INFO, mode, $"Successfully handled '{WindowLib.GetProcessName(hWndGame)}'!");
                }
            }
            catch
            {
                Settings.WriteInLogs(Settings.ErrorCategory.ERROR, mode, $"An error occured when changing style of '{WindowLib.GetProcessName(hWndGame)}'!");
            }
        }