Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Maximized window mode launches in fullscreen

Discussion in 'Editor & General Support' started by MBlomme, Dec 26, 2019.

  1. MBlomme

    MBlomme

    Joined:
    Dec 18, 2017
    Posts:
    11
    Hi everyone!

    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?

    Thank you very much for your answers!
     
  2. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,795
    Hey there @MBlomme, try setting fullscreen mode to windowed and setting "allow fullscreen" to false. Hope that helps!
     
  3. MBlomme

    MBlomme

    Joined:
    Dec 18, 2017
    Posts:
    11
    Hey @TreyK-47 , thanks for your reply!

    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...

    Thanks for your help!
     
  4. kevin-masson

    kevin-masson

    Joined:
    Sep 24, 2018
    Posts:
    71
    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.

    Configure your resolution like this:

     
    biruktes1 likes this.
  5. Tom-Mensink

    Tom-Mensink

    Joined:
    Jul 27, 2017
    Posts:
    17
    Hi, I have the same problem.

    @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 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.
     
  6. kevin-masson

    kevin-masson

    Joined:
    Sep 24, 2018
    Posts:
    71
    I forgot to mention it only work for Windows with single instance.
     
  7. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    500
    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

    Code (CSharp):
    1. using System;
    2. using System.Runtime.InteropServices;
    3. using UnityEngine;
    4.  
    5. namespace VGS.VLR
    6. {
    7.     public class VR_OnApplicationStart : MonoBehaviour
    8.     {
    9.         private const int SW_MAXIMIZE = 3;
    10.         private const int SW_MINIMIZE = 6;
    11.  
    12.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    13.         private static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);
    14.  
    15.         private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
    16.  
    17.         [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    18.         private static extern bool EnumWindows(EnumWindowsProc callback, IntPtr extraData);
    19.  
    20.         [DllImport("user32.dll")]
    21.         private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
    22.  
    23.         [DllImport("user32.dll")]
    24.         private static extern IntPtr GetActiveWindow();
    25.  
    26.         private HandleRef unityWindowHandle;
    27.  
    28.         public void Awake()
    29.         {
    30.             if (!Application.isEditor)
    31.             {
    32.                 PlayerPrefs.SetInt("Fullscreen mode_h3981298716", 0);
    33.                 Screen.fullScreen = false;
    34.                 Screen.fullScreenMode = FullScreenMode.Windowed;
    35.                 Invoke("MaximizeAppWindow", 0.2f);
    36.             }
    37.         }
    38.  
    39.         public void MaximizeAppWindow()
    40.         {
    41.             EnumWindows(EnumWindowsCallBack, IntPtr.Zero);
    42.             ShowWindow(unityWindowHandle.Handle, SW_MAXIMIZE);
    43.         }
    44.  
    45.         public bool EnumWindowsCallBack(IntPtr hWnd, IntPtr lParam)
    46.         {
    47.             int procid;
    48.             GetWindowThreadProcessId(new HandleRef(this, hWnd), out procid);
    49.  
    50.             int currentPID = System.Diagnostics.Process.GetCurrentProcess().Id;
    51.  
    52.             new HandleRef(this, System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle);
    53.  
    54.             if (procid == currentPID)
    55.             {
    56.                 unityWindowHandle = new HandleRef(this, hWnd);
    57.                 return false;
    58.             }
    59.  
    60.             return true;
    61.         }
    62.     }
    63. }
     
    Last edited: Mar 25, 2021
    visualjoy likes this.
  8. snowinrain

    snowinrain

    Joined:
    Jan 17, 2016
    Posts:
    15
    Thanks, this works for me
     
    visualjoy likes this.
  9. GandhiOfTheFoG

    GandhiOfTheFoG

    Joined:
    Oct 17, 2018
    Posts:
    6
    2020.3.9f and still is a problem...
     
  10. baize97

    baize97

    Joined:
    Jun 23, 2020
    Posts:
    30
    Hi @GXMark, user32.dll does not work on Apple systems. How should Apple systems handle windows?
     
  11. Morphus74

    Morphus74

    Joined:
    Jun 12, 2018
    Posts:
    174
    Still no official fix for that?
     
  12. caxapexac

    caxapexac

    Joined:
    Feb 27, 2018
    Posts:
    6
    +1
    Still no fix, 2020.3.19
     
  13. tlt

    tlt

    Joined:
    Nov 16, 2011
    Posts:
    10
    +1
    still no fix too
     
  14. CoDeRYiLmAz

    CoDeRYiLmAz

    Joined:
    May 3, 2021
    Posts:
    1
    +1
    No fix again, 2020.3.28f1
     
  15. andy_pondy

    andy_pondy

    Joined:
    Dec 11, 2017
    Posts:
    5
    +1
    still waiting for fix 2020.3.32f1
     
  16. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,503
    Can anyone file a bug report on this?
     
  17. jorrit-de-vries

    jorrit-de-vries

    Joined:
    Aug 7, 2009
    Posts:
    71
    I have filed a bug report.
     
  18. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,503
    Hey, it seems some wires got crossed and the bug was mistakenly closed. I asked QA to reopen it and assign it to my team for fixing.

    If that ever happens again, feel free to respond to forum threads like this - we can definitely fix mistakes like that.
     
  19. jorrit-de-vries

    jorrit-de-vries

    Joined:
    Aug 7, 2009
    Posts:
    71
    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*.
     
  20. Untrustedlife

    Untrustedlife

    Joined:
    Apr 21, 2020
    Posts:
    78
    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.
     
  21. Untrustedlife

    Untrustedlife

    Joined:
    Apr 21, 2020
    Posts:
    78
    The "Solution" im running with right now is a global variable that knows when the game is first booted up that is checked on the main menu and then it checks if the players has set settings to windowed and if so centers and makes the window slightly smaller than the actual screen size (equal open space on all sides) so the player can cleary see that they should maximize if they want it to take up the whole screen. No window sizes I tried seem to mimic a maximized screen so.

    This obviously isnt a problem for players who are in full screen mode. Because full screen is just set to the resolution you give it.
     
  22. Hayden-Verbrec

    Hayden-Verbrec

    Joined:
    Sep 14, 2022
    Posts:
    10
    These settings are extremely unintuitive and could use some better clarity baked in, even if it was simply changing the names of each option.
     
    Last edited: Feb 6, 2023
  23. diogoico

    diogoico

    Joined:
    Dec 21, 2017
    Posts:
    3
    Still happening nowadays.

    The Unity I'm using is 2022.3.4f1 version.
     
  24. Atomiz2002

    Atomiz2002

    Joined:
    Feb 2, 2020
    Posts:
    9
  25. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    500
    Just looking at this forum and thinking why is this still an issue opening a maximized window screen in all platforms?