Search Unity

Windowed mode goes under windows taskbar

Discussion in 'Windows' started by Kiour_gr, Aug 26, 2021.

  1. Kiour_gr

    Kiour_gr

    Joined:
    Dec 6, 2017
    Posts:
    18
    Hello,
    My game is set to windowed mode 1920*1080.
    When the game loads, it loads on all of the screen at the bottom part is under the taskbar.
    Once I press the maximize button or double click the top part of my game, the game resizes to full screen but takes in consideration Windows taskbar.
    Is there a way to set this by default?
    or is the a way to tell my application to execute the windows maximize window command?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,678
    You could send WM_SYSCOMMAND/SC_RESTORE win32 message to the app window by P/Invoking into PostMessage API.
     
  3. Kiour_gr

    Kiour_gr

    Joined:
    Dec 6, 2017
    Posts:
    18
    Thank for replying, could you please explain how I can send the message or where I can read about sending a windows message?
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,678
    Yeah, you'd call PostMessageW windows API:

    Code (csharp):
    1. [DllImport("user32.dll")]
    2. static extern IntPtr GetActiveWindow();
    3.  
    4. [return: MarshalAs(UnmanagedType.Bool)]
    5. [DllImport("user32.dll", SetLastError = true)]
    6. static extern bool PostMessageW(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
    7.  
    8. const uint WM_SYSCOMMAND = 0x0112;
    9. const uint SC_MAXIMIZE = 0xF030;
    10.  
    11. void Awake()
    12. {
    13.     PostMessageW(GetActiveWindow(), WM_SYSCOMMAND, new IntPtr(SC_MAXIMIZE), IntPtr.Zero);
    14. }
     
    Kiour_gr likes this.
  5. baize97

    baize97

    Joined:
    Jun 23, 2020
    Posts:
    30
    Excuse me, how to achieve the same task under the Apple system?
    @Tautvydas-Zilys
     
    Last edited: Aug 31, 2021
  6. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,678
    Unfortunately, I'm not very familiar with macOS windowing APIs, but I suspect you'd have to do something similar.
     
    baize97 likes this.
  7. Kiour_gr

    Kiour_gr

    Joined:
    Dec 6, 2017
    Posts:
    18

    Fantastic! Exactly what I wanted, thank you very much.