I am currently developing a standalone app, and I need it to be launched as a maximized window (a window that takes the maximal possible space, still displaying the taskbar and window top bar)
In order to do so, I set the Fullscreen Mode parameter from the Player Settings to Maximized Window, logical.
However, when I build my player with this parameter, the app launches in fullscreen mode…
What I checked :
Screen.fullScreenMode is never used in my scripts
I deleted the register keys associated with the app in Windows’ Regedit
Does anyone have a solution to this? Or maybe what I want is not Unity’s Maximized Window mode?
Just returned to my project to try your solution, but I don’t have any “allow fullscreen” parameter in the Player Settings, were you talking about a field named allowFullscreen that I should set with a script?
Also by setting fullscreen mode to windowed I have to manually enter the window size in the Player Settings, but what I want is the app to automatically be the biggest possible window, which is as I understand it the definition of the Maximized Window fullscreen mode…
Hi @MBlomme , I found a way to maximize the window when starting a standalone Unity game. Simply put this script in your projec and replace “APP_NAME” by a regex that match your Application.productName.
@TreyK-47 your solution does not work for me. Unity 2019.4.8f1.
Also exiting the full screen window does not work.
So this are actually two Unity bugs I assume.
@kevin-masson_1 your solution resulted in an application hang-up, maybe I did something wrong with the APP_NAME or I should have checked Force Single Instance (which I do not want, I want more instances). Did not attempt to bug trace.
I can’t believe that we are in Unity 2020.3.1f1 (LTS) and this same issue existed like 3 years ago in unity versions.
Maximized Window should maximize the window on startup leaving the taskbar showing.
FullScreen should maximize the window on startup taking up the entire monitor screen.
TreyK ? Is this a problem or oversight of unity?
You can achieve this in windows 10 (unity 2020.x) with the following setup and code …
Resolution Settings
Fullscreen Mode : Fullscreen Window
Default Is Native Resolution : Tick
Mac Retina Support : Not Tick
Run in Background : Tick
Standalone Player Options
Capture Single Screen : Not Tick
Use Player Log : Tick
Resizable Window : Tick
Visible in Background : Tick
Allow Fullscreen Switch : Tick
Force Single Instance : Not Tick
Use DXGI Flip Model Swapchain for D3D11 : Tick
Attach this script to a game object in your hierarchy e.g. ApplicationStart
Code
using System;
using System.Runtime.InteropServices;
using UnityEngine;
namespace VGS.VLR
{
public class VR_OnApplicationStart : MonoBehaviour
{
private const int SW_MAXIMIZE = 3;
private const int SW_MINIMIZE = 6;
[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);
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern IntPtr GetActiveWindow();
private HandleRef unityWindowHandle;
public void Awake()
{
if (!Application.isEditor)
{
PlayerPrefs.SetInt("Fullscreen mode_h3981298716", 0);
Screen.fullScreen = false;
Screen.fullScreenMode = FullScreenMode.Windowed;
Invoke("MaximizeAppWindow", 0.2f);
}
}
public void MaximizeAppWindow()
{
EnumWindows(EnumWindowsCallBack, IntPtr.Zero);
ShowWindow(unityWindowHandle.Handle, SW_MAXIMIZE);
}
public bool EnumWindowsCallBack(IntPtr hWnd, IntPtr lParam)
{
int procid;
GetWindowThreadProcessId(new HandleRef(this, hWnd), out procid);
int currentPID = System.Diagnostics.Process.GetCurrentProcess().Id;
new HandleRef(this, System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
if (procid == currentPID)
{
unityWindowHandle = new HandleRef(this, hWnd);
return false;
}
return true;
}
}
}
Sorry, it took a while… I noticed the report got opened for the second time, which seems to be from Unity internal actions.
The setting for Windows is, without reading the documentation, rather unintuitive.
I managed to get my own solution to open the application in a windowed mode and maximize the window upon initialization, but this would be more robust - and probably as important, more intuitive - if it would be part of the window creation routine when Fullscreen Mode is set to Maximized Window.
What was your solution?
It bugs me when unity starts just slightly offcenter in the window. Half the time the players dont realize they should probably maximize. I need a fix.