コード例 #1
0
ファイル: WindowFactory.cs プロジェクト: tehrelt/Playnite
 public static void BringToForeground(WindowBase window)
 {
     if (!window.Activate())
     {
         window.Topmost = true;
         window.Topmost = false;
     }
 }
コード例 #2
0
 public static WindowBase                show(this WindowBase window)
 {
     try
     {
         window.visible(true);
         window.Activate();
     }
     catch (Exception ex)
     {
         ex.log("[window.show]");
     }
     return(window);
 }
コード例 #3
0
        public static void RestoreWindow(WindowBase window)
        {
            try
            {
                // This is the only reliable method that also doesn't result in issues like this:
                // https://www.reddit.com/r/playnite/comments/f6d73l/bug_full_screen_ui_wont_respond_to_left_stick/
                // Adapted from https://ask.xiaolee.net/questions/1040342
                window.Show();
                if (!window.Activate())
                {
                    window.Topmost = true;
                    window.Topmost = false;
                }

                if (window.WindowState == WindowState.Minimized)
                {
                    window.WindowState = WindowState.Normal;
                }

                //Get the process ID for this window's thread
                var interopHelper      = new WindowInteropHelper(window);
                var thisWindowThreadId = Interop.GetWindowThreadProcessId(interopHelper.Handle, IntPtr.Zero);

                //Get the process ID for the foreground window's thread
                var currentForegroundWindow         = Interop.GetForegroundWindow();
                var currentForegroundWindowThreadId = Interop.GetWindowThreadProcessId(currentForegroundWindow, IntPtr.Zero);

                //Attach this window's thread to the current window's thread
                Interop.AttachThreadInput(currentForegroundWindowThreadId, thisWindowThreadId, true);

                //Set the window position
                Interop.SetWindowPos(interopHelper.Handle, new IntPtr(0), 0, 0, 0, 0, Interop.SWP_NOSIZE | Interop.SWP_NOMOVE | Interop.SWP_SHOWWINDOW);

                //Detach this window's thread from the current window's thread
                Interop.AttachThreadInput(currentForegroundWindowThreadId, thisWindowThreadId, false);
            }
            catch (Exception e)
            {
                logger.Error(e, "Failed to restore window.");
            }
        }