- Home /
Find if windowed mode has been maximised
Hey everyone,
I am running into an issue where i am trying to detect when a user has maximised a unity window from windowed mode. I've tried comparing Screen.height / width against Screen.currentResolution but when maximising from windowed mode, Screen.height takes into account the task bar so it never reaches currentResolution.height.
Is there a event or another way i can check to see if the user has maximised the window? I cant seem to find anything on the internet.
This is a windows project.
Cheers!
Do you mean a maximized window or fullscreen mode? A maximized window is still a window. So it could have any size the user want. If you're looking for the maximized status of the native OS window, you would need to use native OS API methods to deter$$anonymous$$e the window state. For windows you would have to dive into pinvoke calls to the WinAPI. This should be a good start. Installing hooks can be problematic but would directly give you a callback when it got maximized. Using GetWindowPlacement lets you query the maximized state on demand.
Though you should ask yourself if you really need to know this. If your window is resizable, the user would have full control over moving and resizing the window to any size. A maximized window is just "one" window size from the applications perspective. The special "maximized state" is just relevant for the OS.
So what's the exact usecase?
Hey @Bunny83,
I mean maximized window, not full screen.
So use case is we are designing an editor i guess you could say similar to Unity. We have limited the user to stay at a ratio of 16:9 when resizing their windowed window, if they in fact choose to go windowed and not fullscreen. So whether they stretch vertically or horizontally, it will always stay at a 16:9 ratio to stop stretching (As we do no support dynamic windows yet).
But if they double click the top tab of the window and its maximised to their current screen res, thats when things get a little weird. Hence why i would like to know when it is done to try and handle it.
It is something we would very much like. It is not necessary or a must have so just doing research and seeing if it is worth / good enough to implement.
Answer by Zaeran · Jan 06, 2021 at 06:19 AM
You can't tell if the window itself has been maximised or not, because Unity doesn't give you that low level access to their windows.
What you could possibly do is use Screen.width/height, or Display.displays[0].renderedWidth/Height to check the size of the window when it comes back into focus after being maximised, using OnApplicationFocus(), and then use that to determine what behaviour you want to happen