0

I have a project that automates/controls other Window applications by simulating keystrokes. To simulate keystrokes, I need to bring the window of that application to the front. When this is in progress, you can see the whole process on the screen.

However, I want to have a fake full screen to cover that up. If this is possible, I would also like to display something on the fake full screen, such as the progress bar.

Any suggestion would be helpful. Thanks

pioneer
  • 37
  • 8

2 Answers2

0

What you want to achieve is to make your main form be displayed in "windowed full screen" mode that is right ?

So in order to do that, you need to set your window size to your screen size.

A way to do it would be the following, in your WPF class :

this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;

Or

this.WindowState = WindowState.Maximized;

To bring a window forward, you can also use :

myWindow.Activate();

or

this.TopMost = true;

I hope this will be helpful.

Dorian Naaji
  • 116
  • 1
  • 6
0

To prevent other windows overlaying your window when it is deactivated you can add the method, I'd use the solution at WPF Always On Top (I've it used before and it worked well for me), to the Deactivated event of the window:

private void Window_Deactivated(object sender, EventArgs e)
{
    Window window = (Window)sender;
    window.Topmost = true;
}

If you would like to show a progress bar in a fullscreen window when your operation is in progress, you could do something like:

private Window CreateFullScreenLoadingBar()
{
    Window fullscreenWindow = new YourLoadingBarWindow();

    fullscreenWindow.WindowStyle = WindowStyle.None;
    fullscreenWindow.WindowState = WindowState.Maximized;
    fullscreenWindow.ResizeMode = ResizeMode.NoResize;
    fullscreenWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;

    fullscreenWindow.Deactivated += delegate (object sender, EventArgs e)
    {
        Window window = (Window)sender;
        window.Topmost = true;
    };            
}

Usage:

...
Window loadingBar = CreateFullScreenLoadingBar();
fullscreenWindow.Show();
fullscreenWindow.Activate();

// Your code

loadingBar.Close();
...

Where YourLoadingBarWindow is a window containing a progress bar or whatever you want the user to see.

Alfie
  • 1,903
  • 4
  • 21
  • 32
  • Thanks for your response. If I use setforeground() to another application, would this fake window be underneath that? In other words, this fake window won't always be on the top? – pioneer May 23 '19 at 19:02
  • @M no this full screen window should always be on top, because of `window.Topmost = true` is executed when the window is deactivated. I've tested it briefly and it seemed to work well – Alfie May 23 '19 at 19:07
  • Okay I will give it try today – pioneer May 24 '19 at 12:55
  • Unfortunately, "Topmost" method did not work. A full size window works, but when the program Setforeground() another window, the full size window goes away. – pioneer May 24 '19 at 13:32
  • @MHwang Have you tried using the https://learn.microsoft.com/en-us/dotnet/api/system.windows.window.activate?redirectedfrom=MSDN&view=netframework-4.8#System_Windows_Window_Activate method rather than `SetForground()`? – Alfie May 24 '19 at 13:35
  • https://stackoverflow.com/a/3787098/10772348 @TheCodeKing mentions in the comment that SetForground() needs used to control an application from another process, which is my case – pioneer May 24 '19 at 13:59
  • @MHwang Ah okay, just seen this https://social.msdn.microsoft.com/Forums/vstudio/en-US/697915fe-7cc2-4c6f-8f96-ecc6a4924858/always-on-top-even-in-fullscreengames?forum=wpf, where they use window.Active() at the end of the method subsribed to `Window.Deactivated` - perhaps that might make a difference? If not I'm not too sure what else to try :( – Alfie May 24 '19 at 14:04
  • @MHwang Also If that doesn't work I've just had an idea to use a `Popup` control (https://learn.microsoft.com/en-us/dotnet/framework/wpf/controls/popup-overview) as the whole point of a popup is to always overlay windows. However the only issue with a `Popup` is the fact that it can only cover up to 75% of the screen - Not ideal but definitely a potential work around to your issue – Alfie May 24 '19 at 14:40