I am creating a transparent messaging Application which should be overlayed over the Desktop. I'm currently using Unity for the development (but this should be irrelevant because I think its a problem with Windows 11). I upgraded lately to Windows 11 and since then (I think) these problems occur.
In Unity I have a script which turns my Application to a fullscreen transparent Window. But for some reason the "whiteness" of any color displayed also defines its transparency on the final build, with black ==> full transparent and white ==> full opaque.
I tested this with multiple different Projects from different sources all with the same result.
I am not too experienced with the WindowsAPI and I don't know if this is a new restriction of Windows 11 or if I am missing something here...
I would appreciate if someone wants to share some thoughts with me.
Here is the relevant Code which is used to create the transparent windows and 2 Screenshots displaying the issue.
private const int GWL_EXSTYLE = -20;
private const long WS_EX_LAYERED = 0x00080000L;
private const long WS_EX_TRANSPARENT = 0x00000020L;
private const uint LWA_COLORKEY = 0x00000001;
private const uint LWA_ALPHA = 0x00000002;
private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
public void Start()
{
#if !UNITY_EDITOR
m_HWnd = GetActiveWindow();
var margins = new MARGINS() {cxLeftWidth = -1};
DwmExtendFrameIntoClientArea(m_HWnd, ref margins);
SetLayeredWindowAttributes(m_HWnd, 0, 0, LWA_ALPHA);
SetWindowPos(m_HWnd, HWND_TOPMOST, 0, 0, 0, 0, 0);
#endif
Application.runInBackground = true;
}
public void Update()
{
m_ClickThroughProvider.Update(this.gameObject);
SetClickThrough(m_ClickThroughProvider.GetClickThrough());
}
private void SetClickThrough(bool shouldClickThrough)
{
#if !UNITY_EDITOR
if (shouldClickThrough)
SetWindowLongPtrA(m_HWnd, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT);
else
SetWindowLongPtrA(m_HWnd, GWL_EXSTYLE, WS_EX_LAYERED);
#endif
}
Here the first Screenshot how it should look like (in the Unity Editor):
Here the second Screenshot how the build application looks like (no changes in the UI only the code listed above runs in the build (and not in the Unity Editor)):

