Ejemplo n.º 1
0
        /// <summary>
        /// Event handler that monitors Windows foreground window changes in order to prevent the annoying problem of
        /// Steam stealing focus from LB after some games exit (at which time LB/BB should be the active Window).
        /// This is only enabled if the 'PreventSteamFocusStealing' setting is enabled.
        /// </summary>
        /// <param name="sender">The object who issued the event.</param>
        /// <param name="windowHeader">The title of the newly activated window.</param>
        /// <param name="hwnd">The handle of the newly activated window.</param>
        private void OnActiveWindowChanged(object sender, string windowHeader, IntPtr hwnd)
        {
            if (hwnd == Utilities.GetLaunchBoxProcess().MainWindowHandle)
            {
                _lastTimeLbInForeground = DateTime.Now;
                return;
            }

            if (hwnd == SteamProcessInfo.SteamProcess.MainWindowHandle)
            {
                var timeSinceLbGotFocus = DateTime.Now.Subtract(_lastTimeLbInForeground);
                if (timeSinceLbGotFocus >= TimeSpan.FromSeconds(Config.Instance.TotalSecondsToPreventSteamFocus))
                {
                    return;
                }

                Logger.Info("Forcing LaunchBox window into the foreground because Steam window stole focus.");
                ActiveWindow.SetForegroundWindow(Utilities.GetLaunchBoxProcess().MainWindowHandle);
                DisableActiveWindowHook();
            }
        }