Unity3D borderless window / maximized fullscreen

Hi all,

I am trying to add “borderless window” / “maximized fullscreen” to a list of graphical fullscreen options. I know that (on Windows) launching the exe with -popupwindow will give a borderless window and keep it correct while I change resolutions and configure other graphical settings. Rather than ask the players to relaunch the game every time they want to switch from a window with a border and a window without a border I want them to be able to change it in the in-game graphics menu.

I have resorted to using user32.dll functions to change the window properties like so;

var bounds = Screen.PrimaryScreen.Bounds;
SetWindowLong(GetForegroundWindow(), GWL_STYLE, 1);
bool result = SetWindowPos(GetForegroundWindow(), 0, 0, 0, bounds.Width, bounds.Height, SWP_SHOWWINDOW);

It seems to work but not very well (it doesn’t seem to work all the time and it doesn’t work after setting the window to other resolutions). It makes me wonder; is Unity3D aggressively setting the window style after I try to change it?

If so, is there any way to work around this or (much, much more prefferably) is there any way for me to access the properties set by launching with “-popupwindow”? (I’m crossing my fingers for a response from a Unity dev)

Currently this is quite a pain in the behind; for me as a developer and more importantly for players who will have to use the graphics settings. Any help would be appreciated, thanks!

Further testing shows launching with -popupwindow will actively kill the borders any time I move the window if I add them using;

IntPtr window = GetForegroundWindow();
SetWindowLong(window, GWL_STYLE, WS_CAPTION | WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX);
SetWindowPos(window, -2, 0, 0, 600, 480, WP_SHOWWINDOW);
DrawMenuBar(window);

This is very weird; I’m more and more inclined to believe Unity3D is aggressively setting the window properties any time the window is moved. Does anyone know how to get a callback when the window is moved? (so I can aggressively set it back)

However I’m still more than happy to access the properties set by -popupwindow if at all possible.