Minimizing and maximizing by script

In a standalone player, is it possible to force minimizing the screen by scripting?

What I am trying to do is minimizing the screen when some event happens, and then maximising the screen whe I read a value from a text file.

Maybe i have to write a plugin, in that case how does it work?


Similar as proposed @green_core but a little bit easier way to minimize is described here

In the end you will have something like this:

private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
private static extern IntPtr GetActiveWindow();

public void OnMinimizeButtonClick()
        ShowWindow(GetActiveWindow(), 2);

You can do anything with window by using WinAPI. But you have to get window handle to do it.
In usual .NET application you can get them by this way:

var handle Process.GetCurrentProcess().MainWindowHandle

But it doesn’t work in unity.
So, i use another way to get the handle. I enumerate all windows by function EnumWindowsProc
and i get process id of each window by GetWindowThreadProcessId. When i find window with pid, that equals to pid of unity i can manipulate by unity window. Resize, move, minimize, etc.

To minimize window you can use ShowWindow function.

To use WinAPI functions you have to import them:

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);

private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool EnumWindows(EnumWindowsProc callback, IntPtr extraData);

Switch that boolean argument to True for fullscreen and False for windowed.