Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

[SOLVED!] Windows: Transparent window with opaque contents (LWA_COLORKEY)?

Discussion in 'Windows' started by krougeau, May 2, 2015.

  1. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,714
    Using four zeroes should reset it to initial state, I think (that's the impression I've got from reading the link I posted - I did not try it).
     
  2. LazyDog_Rich

    LazyDog_Rich

    Joined:
    Apr 27, 2014
    Posts:
    70
    Hi! Sorry for necro this old post, but this is the only thing I found about this...
    I have problems making the window click-through unless there's some collider or UI in front.

    I can have a fully click-through window, or a non-click-throughable window

    What I got so far is that if I use:
    SetWindowLong(hwnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
    In the Start (). I have a click-able and transparent scene

    And if I use:
    SetWindowLong(hwnd, -20, 524288 | 32);
    In the Start(), I will have a transparent and click-through scene

    But I tried change between them using a Input key, and I can change from, click-able to click-through, but I cannot change from click-through to clickable...

    I was debbuging the whole time, so I know the input Im using is being detected, but still dont work :(

    This is the whole code:
    Code (CSharp):
    1. using System;
    2. using System.Runtime.InteropServices;
    3. using UnityEngine;
    4.  
    5. public class TransparentWindow : MonoBehaviour
    6. {
    7.     [SerializeField]
    8.     private Material m_Material;
    9.  
    10.     private struct MARGINS
    11.         {
    12.         public int cxLeftWidth;
    13.         public int cxRightWidth;
    14.         public int cyTopHeight;
    15.         public int cyBottomHeight;
    16.         }
    17.  
    18.     [DllImport("user32.dll")]
    19.     private static extern IntPtr GetActiveWindow();
    20.  
    21.     [DllImport("user32.dll")]
    22.     private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
    23.  
    24.     [DllImport("user32.dll")]
    25.     static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
    26.  
    27.     [DllImport("user32.dll", EntryPoint = "SetLayeredWindowAttributes")]
    28.     static extern int SetLayeredWindowAttributes(IntPtr hwnd, int crKey, byte bAlpha, int dwFlags);
    29.  
    30.     [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
    31.     private static extern int SetWindowPos(IntPtr hwnd, int hwndInsertAfter, int x, int y, int cx, int cy, int uFlags);
    32.  
    33.     [DllImport("Dwmapi.dll")]
    34.     private static extern uint DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margins);
    35.  
    36.     const int GWL_STYLE = -16;
    37.     const uint WS_POPUP = 0x80000000;
    38.     const uint WS_VISIBLE = 0x10000000;
    39.     const int HWND_TOPMOST = -1;
    40.  
    41.     void Start()
    42.         {
    43. #if !UNITY_EDITOR // You really don't want to enable this in the editor..
    44.  
    45.         var margins = new MARGINS() { cxLeftWidth = -1 };
    46.         var hwnd = GetActiveWindow();
    47.  
    48.         SetWindowLong(hwnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
    49.  
    50.         DwmExtendFrameIntoClientArea(hwnd, ref margins);
    51.  
    52. #endif
    53.         }
    54.  
    55.     private bool clickThrough;
    56.  
    57.     void ChangeTransparency ()
    58.         {
    59.         var margins = new MARGINS() { cxLeftWidth = -1 };
    60.         var hwnd = GetActiveWindow();
    61.         if(!clickThrough)
    62.             {
    63.             Debug.Log("Window is click-able now");
    64.             margins = new MARGINS() { cxLeftWidth = 0, cxRightWidth = 0, cyTopHeight = 0, cyBottomHeight = 0 };
    65.             SetWindowLong(hwnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
    66.             }
    67.         else
    68.             {
    69.             Debug.Log("Window is click-through now");
    70.             int fWidth = Screen.width;// is not
    71.             int fHeight = Screen.height;// is not
    72.             SetWindowLong(hwnd, -20, 524288 | 32);//is not //GWL_EXSTYLE=-20; WS_EX_LAYERED=524288=&h80000, WS_EX_TRANSPARENT=32=0x00000020L
    73.             SetLayeredWindowAttributes(hwnd, 0, 255, 2);//is not // Transparency=51=20%, LWA_ALPHA=2
    74.             SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, fWidth, fHeight, 32 | 64); //is not //SWP_FRAMECHANGED = 0x0020 (32); //SWP_SHOWWINDOW = 0x0040 (64)
    75.             }
    76.         DwmExtendFrameIntoClientArea(hwnd, ref margins);
    77.         }
    78.  
    79.     void Update ()
    80.         {
    81.         if(Input.GetKeyDown(KeyCode.Q))
    82.             {
    83.             clickThrough = !clickThrough;
    84.             ChangeTransparency ();
    85.             }
    86.         }
    87.  
    88.     void OnRenderImage(RenderTexture from, RenderTexture to)
    89.         {
    90.         Graphics.Blit(from, to, m_Material);
    91.         }
    92. }
     
  3. LazyDog_Rich

    LazyDog_Rich

    Joined:
    Apr 27, 2014
    Posts:
    70
  4. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Thanks, Tautvydas-Zilys for the script! is working.

    My default resolution is 800x600. But when I apply this "TransparentWindow" the resolution change to 816x639 losing the 4:3 proportion. Any idea to how to resolve this?
     
  5. baksarbed

    baksarbed

    Joined:
    Sep 29, 2016
    Posts:
    2
    Can you tell me, please, how can I do it for Mac OS?
     
  6. AzkabanProfessor

    AzkabanProfessor

    Joined:
    Mar 9, 2017
    Posts:
    7
    I enable aero on windows7,but it is tranparent on starting,then become black background quickly. How can I fix this? On windows10,it's fine.
     
  7. Jed_500

    Jed_500

    Joined:
    Oct 30, 2013
    Posts:
    2
    necro.... I know but for completeness zalo10 solution works fine just to add for ui detection add:-

    Code (CSharp):
    1. public bool OverUI() { //Use sparingly
    2.         //Set up the new Pointer Event
    3.         PointerEventData m_PointerEventData = new PointerEventData(EventSystem.current);
    4.         m_PointerEventData.position = Input.mousePosition;
    5.         List<RaycastResult> results = new List<RaycastResult>();
    6.         EventSystem.current.RaycastAll(m_PointerEventData, results);
    7.         if (results.Count > 0) return true;
    8.         return false;
    9.     }
    and change:

    Code (CSharp):
    1. clickThrough = !Physics.Raycast (mainCamera.ScreenPointToRay (Input.mousePosition).origin,
    2.                 mainCamera.ScreenPointToRay (Input.mousePosition).direction, out hit, 100,
    3.                 Physics.DefaultRaycastLayers);
    to:

    Code (CSharp):
    1. clickThrough = !Physics.Raycast (mainCamera.ScreenPointToRay (Input.mousePosition).origin,
    2.                 mainCamera.ScreenPointToRay (Input.mousePosition).direction, out hit, 100,
    3.                 Physics.DefaultRaycastLayers)&&!OverUI();
     
  8. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    it's working with multi windows ?
     
  9. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    241
    Just to note, this works in 2018.3.b12, but not in 2019.1.0a11 (yet)
     
  10. EvalDaemon

    EvalDaemon

    Joined:
    Aug 8, 2013
    Posts:
    107
    You mean multi-monitor? If so YES I have it working with up to 8 monitors.
     
  11. EvalDaemon

    EvalDaemon

    Joined:
    Aug 8, 2013
    Posts:
    107
    Any idea why? I'm still running 2018 and that could be a deal breaker for me on a 2019 upgrade.
     
  12. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,714
  13. EvalDaemon

    EvalDaemon

    Joined:
    Aug 8, 2013
    Posts:
    107
    Is anyone else having problems running this using Player Settings -> Scripting Runtime Version .NET 4.x Equivalent?
     
  14. EvalDaemon

    EvalDaemon

    Joined:
    Aug 8, 2013
    Posts:
    107
    I'll answer my own question. If you change to Scripting Runtime = >net 4.x you need to also set the Api Compatibility Level to .NET 4.x
     
  15. BackgroundMover

    BackgroundMover

    Joined:
    May 9, 2015
    Posts:
    241
    It's working again in 2019.1.7! (and 2019.2.0b6 and 2019.3.0a2). Big thanks to Unity for keeping this awesome functionality alive.

    Per Tautvydas-Zilys, you have to make sure to UNCHECK "Use DXGI Flip Model Swapchain for D3D11" under Player Settings -> Resolution and Presentation. (I also had to tweak the shader to use alpha instead of color key, and havent tried clickthrough yet but the transparency is there, or NOT there I guess!)
     

    Attached Files:

    Weightless likes this.
  16. EvalDaemon

    EvalDaemon

    Joined:
    Aug 8, 2013
    Posts:
    107
    Ya you beat me to it, I was just looking at 2019.1.7 release notes.

    Windows: Added a Player Setting for reverting to BltBlt swapchain model which was used before 2019.1. This enables several scenarios like transparent window to be used once again (1107463, 1152570)
     
  17. baoenzo

    baoenzo

    Joined:
    Jul 6, 2019
    Posts:
    1
    I have a question, how to open the application it's always at the right corner of the desktop.
    I tried many ways on online but it didn't work
     
  18. Foxofthelight

    Foxofthelight

    Joined:
    Nov 20, 2018
    Posts:
    1
    hi i got this to work for my overlay i was making for a game i play (osu!) but if i have the game in fullscreen (which i would like to have because otherwise the game has a little input delay) then the unity window does not overlay it anymore is there a way to fix this?
     
  19. Laperen

    Laperen

    Joined:
    Feb 1, 2016
    Posts:
    1,065
    Needed information on how to do this recently and cant thank enough for this thread and this aswell.

    My current desktop overlay allows the background applications to be interacted with, but loses focus on doing so. When not focused on my desktop overlay, my desktop overlay cannot register input. Is there a way for the desktop overlay to continue registering input while allowing the background applications to be interacted with?
     
  20. JustMaulik007

    JustMaulik007

    Joined:
    Oct 3, 2018
    Posts:
    11
    it's working great but I need to capture screenshot and the current screenshot image does not have the desktop(background) in the screenshot any idea how can I have that desktop background also in the screenshot?
     
  21. mrinalimangal1998

    mrinalimangal1998

    Joined:
    Apr 28, 2020
    Posts:
    1
    Hey Guys,I saw the comments above. This is similar to what I am trying to do .
    I am working on Winforms. I am able to make the form transparent and click-through but When I load my HTML on it,then the page(HTML) itself becomes transparent and since it is click through, I am not able to get the control of HTML buttons ,links etc. as it access the control behind the form. I am new to CEF.
    I want my HTML background to be transparent but not the buttons or labels etc on it and also want to interact with buttons not the window behind it whenever I click on it.
    Thank You
     

    Attached Files:

  22. Slyp

    Slyp

    Joined:
    Oct 27, 2019
    Posts:
    11
    Hello, sorry for the necropost,

    I'm trying to build a transparent window and this solution works great ! But I was wondering if anyone knew how to keep the frame (border) of the window ? (with the minimize/maximize/close buttons etc)

    Thanks
     
  23. vectorealms

    vectorealms

    Joined:
    Dec 28, 2012
    Posts:
    2
    Is there any way to render the image at 100% visibility (to cover icons behind it)? Been messing with the variables but can't find a way.

    See mrinalimangal1998's image 2 posts above.. how would you make his window pure white so you can't see what's behind??
     
  24. vectorealms

    vectorealms

    Joined:
    Dec 28, 2012
    Posts:
    2
    This code to make the background transparent via color key does not work in 2019.3.13f1. The background is just solid black, and doesn't transparent :(

    Can anyone plz advise?

    Code (CSharp):
    1. SetWindowLong(hwnd, -20, 524288 | 32);//is not //GWL_EXSTYLE=-20; WS_EX_LAYERED=524288=&h80000, WS_EX_TRANSPARENT=32=0x00000020L
    2.             SetLayeredWindowAttributes(hwnd, 0, 255, 2);//is not // Transparency=51=20%, LWA_ALPHA=2
    3.             SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, fWidth, fHeight, 32 | 64); //is not //SWP_FRAMECHANGED = 0x0020 (32); //SWP_SHOWWINDOW = 0x0040 (64)
     
  25. Weightless

    Weightless

    Joined:
    Sep 7, 2017
    Posts:
    15
    Have you unchecked "Use DXGI Flip Model Swapchain for D3D11"?
     
  26. Mohipie

    Mohipie

    Joined:
    Aug 8, 2019
    Posts:
    1
    Hi guys !

    Do you know if it's possible to use this kind of script with an Universal Render Pipeline ? For now it works fine without but when I switch, background become black again, transparency seems to not working for now.

    Thanks !
     
    Last edited: May 30, 2020
    MrMahgu likes this.
  27. GreenCubeGames

    GreenCubeGames

    Joined:
    Jan 9, 2015
    Posts:
    19
    Amazing results here, but i need a small window, anyone knows how? I see that with a big screen the desktop performance is low... i want to do a small window to make it better to the user
     
  28. ADepierre

    ADepierre

    Joined:
    Jan 21, 2018
    Posts:
    6
    Got the same problem. Well, actually it's working with URP, the problem comes only when you activate the "post-processing" option on the camera. It deletes the transparency information. See: https://issuetracker.unity3d.com/is...when-post-processing-is-enabled-on-the-camera
     
    Last edited: Jul 23, 2020
  29. HackerNCoder

    HackerNCoder

    Joined:
    Aug 29, 2020
    Posts:
    1
    Is it possible to do this but so it also works on mac/linux? Sorry for the necro.
     
  30. Cypras

    Cypras

    Joined:
    Oct 25, 2013
    Posts:
    64
    Looking for a solution for mac/linux also. Any updates on this?
     
  31. Threeyes

    Threeyes

    Joined:
    Jun 19, 2014
    Posts:
    80
    I tried the code, and they are wonderful! Just one question: I had changed the default cursor, like this:
    upload_2021-2-2_1-33-31.png

    but when My State is "clickThrough", the Cursor sytle fallback to system default cursor. I try to use System.Windows.Forms.Cursor to hide the system cursor, but the result is the same, that's straight, any help will be appreciated.
    upload_2021-2-2_1-33-39.png
     
  32. Epicei

    Epicei

    Joined:
    Jan 24, 2014
    Posts:
    1
    I was wondering how you could use this with multiple monitors. Anyone know?
     
  33. mercuriousreign

    mercuriousreign

    Joined:
    Nov 30, 2017
    Posts:
    5
    Does anyone know how to do this with a multitouch device? seems to calculate clickthrough by calculation Input.mouseposition but I am not sure how to get a touch position. I tried using Input.gettouch(0) (i think this one hangs),
    leantouch and someone's script using wacom's dll but didnt really achieve anything....

    I posted a thread here https://forum.unity.com/threads/transparent-window-app-with-multitouch-not-working.1093282/

    but it looks like everyone is more active in this thread...(though sorry if it is still necro)
     
  34. EvalDaemon

    EvalDaemon

    Joined:
    Aug 8, 2013
    Posts:
    107
    I just noticed an message from Epicei asking about multi monitor support. I think the issue is maybe more about settings then the code. Here is my current working settings as of release 2020.3.4f <DX11>
    unity_trans_2020_3_4f_ss1.png
    unity_trans_2020_3_4f_ss2.png
    unity_trans_2020_3_4f_ss3.png

    Of course NO Splash screen, and you most likely must have pro for this to work as it will force the splash screen.

    On start I use at the very start:

    Screen.fullScreenMode = FullScreenMode.Windowed;

    If you allow it to goto full screen it just won't work correctly.

    I've also noticed for some odd reason, for the very first time, and for no good reason it won't always run with the transparent working properly, windows GUI has some weird identifying itself going on that associates with it that won't work during the first run usually, and occasionally glitches.
     
    Last edited: Apr 16, 2021
  35. mchung123

    mchung123

    Joined:
    Jul 4, 2017
    Posts:
    38
    Offtopic but EvalDaemon were you ever able to get this to work with Bloom Post Processing? I got a transparent window to work with Unity 2020.3 ... however, the post-processing created an artifact.
     

    Attached Files:

  36. illsaveus

    illsaveus

    Joined:
    Nov 19, 2016
    Posts:
    3
    This doesn't work in Universal Windows Platform builds. I've tried, struggled to get the user32.dll symbols working. However, now that I have removed all errors in trying to find the required dlls, the transparency doesn't work. Does any know why this doesn't work in UWP?
     
  37. PoRtCuLLiS

    PoRtCuLLiS

    Joined:
    Apr 17, 2020
    Posts:
    14
    Hello guys, would I be able to get this working with the 2D Renderer (URP) at all? When I use that, the background is no longer transparent, but stays black.
     
  38. CosmicRaven06

    CosmicRaven06

    Joined:
    Jul 18, 2021
    Posts:
    1
    Can someone please tell me how to make the background transparent with opaque content but keeping the edges of the window?

    something like this:
     

    Attached Files:

  39. Warriorforce

    Warriorforce

    Joined:
    May 30, 2018
    Posts:
    1
    Hi, I am trying this code but I get a black background, only click through transparency. I tried different versions of Unity. What could be the cause ? Thankyou.
     
  40. TanijaTheFaun

    TanijaTheFaun

    Joined:
    Aug 16, 2021
    Posts:
    2
    Same issue as Warriorforce, I am using Unity 2021.1.26 and I have everything exactly as explained here and in the Video made by CodeMonkey about this. I tried several solutions on transparency and I also unchecked the "Use DXGI Flip Model Swapchain for D3D11" option.
    I do not mind not having click-through or the Splash screen at the beginning, I just really would like the Desktop to be visible in my application.
    Or is it because I started developing in a 2D project in the beginning?
     
  41. DavidJang

    DavidJang

    Joined:
    Sep 14, 2019
    Posts:
    4
    it is working with URP, just uncheck 'Post-Effect' (Camera&xxxPipelineSetting_Render.asset) and 'HDR'(xxxPipelineSetting.asset)
     
  42. LeonardSchoyen

    LeonardSchoyen

    Joined:
    Jun 30, 2019
    Posts:
    1
    I recreated the technique with the 2D Core template of Unity 2020.3.36f1, and I had the problem where the background was all black. I am not using URP, but disabling HDR in the camera settings still fixed the problem.
     
    BackgroundMover likes this.
  43. Manic_MG

    Manic_MG

    Joined:
    Apr 30, 2015
    Posts:
    13
    I hate to resurrect a pretty old topic, but its such a niche subject I feel this is the only place I can go.

    So I can get URP working with Code Monkeys tutorial, but is this essentially impossible via HDRP? given the rendering methods?
     
  44. Manic_MG

    Manic_MG

    Joined:
    Apr 30, 2015
    Posts:
    13
    Well I can answer my own question now.

    It still works in HDRP!!!!
    Everything else still applies, there's just an additional setting. Just make sure your Color Buffer Format is set to the following on all Quality levels.
    upload_2022-9-23_3-35-19.png
     
    BackgroundMover likes this.
  45. AngelGalaxyOfficial

    AngelGalaxyOfficial

    Joined:
    Apr 10, 2021
    Posts:
    16
    Is there a way to get it working / updated code to have it work with "Use DXGI flip model swap chain for D3D11"?
    upload_2022-11-16_23-30-56.png
    I don't want my game to be hindered performance-wise just for this effect!
     
  46. Meowx

    Meowx

    Joined:
    Oct 10, 2015
    Posts:
    33
    Hey there! Sorry for the necro but this thread seems to remain the only real place for this, lol. I'm using Unity 2019.4.14f, it works fine and is and creates a transparent background with the scene visible, but the window itself behaves like any other Windows app and does not stay on top at all times. If I bring another app to the front, it covers the Unity app up. Using Windows 10, am I missing something? Here's the version of the code I'm using:

    Code (CSharp):
    1. using System;
    2. using System.Runtime.InteropServices;
    3. using UnityEngine;
    4.  
    5. public class TransparentWindow : MonoBehaviour
    6. {
    7.     private struct MARGINS
    8.     {
    9.         public int cxLeftWidth;
    10.         public int cxRightWidth;
    11.         public int cyTopHeight;
    12.         public int cyBottomHeight;
    13.     }
    14.  
    15.     [DllImport("user32.dll")]
    16.     private static extern IntPtr GetActiveWindow();
    17.  
    18.     [DllImport("user32.dll")]
    19.     private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
    20.  
    21.     [DllImport("user32.dll")]
    22.     static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
    23.  
    24.     [DllImport("user32.dll", EntryPoint = "SetLayeredWindowAttributes")]
    25.     static extern int SetLayeredWindowAttributes(IntPtr hwnd, int crKey, byte bAlpha, int dwFlags);
    26.  
    27.     [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
    28.     private static extern int SetWindowPos(IntPtr hwnd, int hwndInsertAfter, int x, int y, int cx, int cy, int uFlags);
    29.  
    30.     [DllImport("Dwmapi.dll")]
    31.     private static extern uint DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margins);
    32.  
    33.     const int GWL_STYLE = -16;
    34.     const uint WS_POPUP = 0x80000000;
    35.     const uint WS_VISIBLE = 0x10000000;
    36.     const int HWND_TOPMOST = -1;
    37.  
    38.     void Start()
    39.     {
    40. #if !UNITY_EDITOR // You really don't want to enable this in the editor..
    41.  
    42.         var margins = new MARGINS() { cxLeftWidth = -1 };
    43.         var hwnd = GetActiveWindow();
    44.  
    45.         SetWindowLong(hwnd, -20, 524288 | 32);
    46.  
    47.         DwmExtendFrameIntoClientArea(hwnd, ref margins);
    48.  
    49. #endif
    50.     }
    51. }
     
  47. Berno

    Berno

    Joined:
    Oct 29, 2014
    Posts:
    40
    I think you've missed the actual step of setting the window to be on top.
    That involves a call to SetWindowPos with the parameter HWND_TOPMOST.
     
    Meowx likes this.
  48. Meowx

    Meowx

    Joined:
    Oct 10, 2015
    Posts:
    33
    Perfect, that was it!! I must have copied a version of the code that didn't have that call. Thank you!!

    ( the updated code, for those interested: )

    Code (CSharp):
    1. using System;
    2. using System.Runtime.InteropServices;
    3. using UnityEngine;
    4.  
    5. public class TransparentWindow : MonoBehaviour
    6. {
    7.     private struct MARGINS
    8.     {
    9.         public int cxLeftWidth;
    10.         public int cxRightWidth;
    11.         public int cyTopHeight;
    12.         public int cyBottomHeight;
    13.     }
    14.  
    15.     [DllImport("user32.dll")]
    16.     private static extern IntPtr GetActiveWindow();
    17.  
    18.     [DllImport("user32.dll")]
    19.     private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
    20.  
    21.     [DllImport("user32.dll")]
    22.     static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
    23.  
    24.     [DllImport("user32.dll", EntryPoint = "SetLayeredWindowAttributes")]
    25.     static extern int SetLayeredWindowAttributes(IntPtr hwnd, int crKey, byte bAlpha, int dwFlags);
    26.  
    27.     [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
    28.     private static extern int SetWindowPos(IntPtr hwnd, int hwndInsertAfter, int x, int y, int cx, int cy, int uFlags);
    29.  
    30.     [DllImport("Dwmapi.dll")]
    31.     private static extern uint DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS margins);
    32.  
    33.     const int GWL_STYLE = -16;
    34.     const uint WS_POPUP = 0x80000000;
    35.     const uint WS_VISIBLE = 0x10000000;
    36.     const int HWND_TOPMOST = -1;
    37.  
    38.     void Start()
    39.     {
    40. #if !UNITY_EDITOR // You really don't want to enable this in the editor..
    41.  
    42.         int fWidth = Screen.width;
    43.         int fHeight = Screen.height;
    44.         var margins = new MARGINS() { cxLeftWidth = -1 };
    45.         var hwnd = GetActiveWindow();
    46.  
    47.         SetWindowLong(hwnd, -20, 524288 | 32);
    48.         SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, fWidth, fHeight, 32 | 64);
    49.         DwmExtendFrameIntoClientArea(hwnd, ref margins);
    50.  
    51. #endif
    52.     }
    53. }
     
  49. liamtechever

    liamtechever

    Joined:
    Mar 29, 2021
    Posts:
    1
    Yea I was wondering the same thing, it feels like it nukes the performance
     
  50. E-Sora

    E-Sora

    Joined:
    May 17, 2020
    Posts:
    1
    I'm trying to work this on windows10 with unity 2022.3.7f1 but couldn't able to make it work yet. I read all 3 threads (from original to here) and this is getting too confusing. Does anyone have the working unity project files? So I can open and see the project in editor and read the working script etc.