Search Unity

Windows Player - Toggling Borderless Mode

Discussion in 'Scripting' started by sgoodrow, Sep 17, 2014.

  1. sgoodrow

    sgoodrow

    Joined:
    Sep 28, 2012
    Posts:
    150
    I am trying to figure out how to implement a toggleable Borderless window mode for the Windows Standalone Player. I am attempting to do this by hooking into user32.dll and making calls to a few internal functions:

    FindWindow
    GetWindowLongPtr
    SetWindowLongPtr
    SetWindowPos

    The reading I have done is mostly straight-forward, it explains (through Microsoft's documentation and various stackexchange posts) that I need to get a reference to my window, and get the window's properties. Then I set or unset the bitmask flags and make a call to set the windows properties. Supposedly, I then need to call the set window position method to cause the window to update.

    Unfortunately this doesn't pan out. The initial setting of the properties DOES in fact update the window, and more-over, the calling to set the window's position causes it to revert some of those settings. The problem is very similar to what is described in this post: http://stackoverflow.com/questions/...nd-ws-caption-from-windows-styles-doesnt-work.

    Is this what Unity is doing? Is Unity intercepting my handling of the window? It's very difficult to know what I am doing wrong if Unity is doing something behind the scenes, so I really require some clarity, please.

    I am happy to share my solution freely. In fact, here is a test project that I am currently working in, feel free to toy around and try to get it to work. Thanks.
     

    Attached Files:

  2. Marko325

    Marko325

    Joined:
    May 23, 2013
    Posts:
    8
    Hey sgoodrow, I'm trying to do the same thing actually. I'm really hoping for some sort of response. When I test launching the exe with -popupwindow it seems to preserve the borderless-ness of the window even while I change resolutions so it makes me wonder if Unity3D is aggressively setting certain window properties.

    Here is the code I'm using;
    Code (CSharp):
    1. var bounds = Screen.PrimaryScreen.Bounds;
    2. SetWindowLong(GetForegroundWindow(), GWL_STYLE, 1);
    3. bool result = SetWindowPos(GetForegroundWindow(), 0, 0, 0, bounds.Width, bounds.Height, SWP_SHOWWINDOW);
    Even if there was some way (no matter how 'dodgy') to access & set the properties set (on the Unity3D side) that are affected by launching with "-popupwindow"; that would also be great. (unless none of this is Unity3D side and I'm lost in the woods)
     
  3. sgoodrow

    sgoodrow

    Joined:
    Sep 28, 2012
    Posts:
    150
    Hi Marko325,

    I don't know the details of what that argument does (-popupwindow). It probably sets some properties in Unity's renderer that reset the window styling when the resolution changes, but I don't know.

    What I do know is that I posted a followup to this thread with my complete solution. It may not include all of the features you'd like, but it also may, and if you haven't seen it I encourage you to take a look. The code is free and explained decently well here: http://www.thewildeternal.com/2014/09/21/devlog-resolution-controller/
     
  4. NightmarexGR

    NightmarexGR

    Joined:
    Jun 7, 2012
    Posts:
    217