Search Unity

Maximized Windows by default

Discussion in 'Windows' started by Gamrek, Jul 23, 2018.

  1. Gamrek

    Gamrek

    Joined:
    Sep 28, 2010
    Posts:
    164
    Hi,

    I am making an application for Standalone Windows. Is there anyway to have a maximised windows screen by default? If I do full screen, the Application Title bar just disappear. I want to keep that bar, but maximised windows when start.

    Here is my settings:
    Fullscreen Mode : Maximized Window
    Default is Native Resolution: True
    Resizable Window: True

    I also tried in script:

    Screen.SetResolution(Screen.width, Screen.height, FullScreenMode.Windowed, 30);

    but this doesn't maximised my window by default. Is there any way to work around it?
     

    Attached Files:

  2. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    You probably want to use
    FullscreenMode.MaximizedWindow
    in your script. However, I tried that and it still didn't work. This seems like a bug to me. You should report it to Unity.

    Sam
     
  3. EthanFischerICS

    EthanFischerICS

    Joined:
    Jan 24, 2018
    Posts:
    2
    Have you figured out a workaround. I'm also facing this issue. Standalone player launches with a gap above the top of the screen and a little between the left of the screen. Clicking the maximize button fills in these gaps, but then it launches this way again next time

    upload_2020-2-10_12-0-1.png
     
  4. beastxplode

    beastxplode

    Joined:
    Nov 26, 2016
    Posts:
    3
    Bump

    Edit: I've scoured the internet trying to find a built-in solution for Unity but it seems like there isn't support to Maximze the window via script. However I found a quick work-around to forcing the game window to maximize using windows dll scripts:

    Code (CSharp):
    1.  
    2. public class Settings : MonoBehaviour {
    3.     [DllImport("user32.dll")]
    4.     private static extern IntPtr GetActiveWindow();
    5.     [DllImport("user32.dll")]
    6.     public static extern bool ShowWindowAsync(int hWnd, int nCmdShow);
    7.  
    8.     void Awake() {
    9.         if (!Screen.fullScreen && !Application.isEditor) // auto maximize window
    10.             ShowWindowAsync(GetActiveWindow().ToInt32(), 3);
    11.     }
    12. }
    This forces the window to maximize on start.

    Heres an enumeration containing all the possible window states (3 being what I used above):
    https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow
    Code (CSharp):
    1. public enum  WindowState : int {
    2.     Hide = 0,
    3.     ShowNormal = 1,
    4.     ShowMinimized = 2,
    5.     ShowMaximized = 3,
    6.     NoActive = 4,
    7.     Show = 5,
    8.     Minimize = 6,
    9.     ShowInNoActive = 7,
    10.     ShowNA = 8,
    11.     Restore = 9,
    12.     ShowDefault = 10
    13. }
     
    Last edited: Oct 30, 2020
    LSDesigner likes this.