0

I'm making this app in Haxe which compiles to C++ code. I'm using the SetLayeredWindowAttributes() function to set the background of the window to be fully transparent. The problem is that this works completely fine only on certain monitors, but not on others.

If I launch the app on my main monitor, which I believe to be 32-bit (if that matters), the background doesn't change at all, or will flicker and then completely disappear until I focus another window.

However, if I connect another monitor and run the app on that one, the background does become transparent, and the transparency persists even if I move it back to my main monitor. Even with the 2nd monitor connected at the same time. If I launch it on the main one, transparency fails.

I have tried changing the color values between 0xFFffffff/0xffffff, etc, but no combination of these work.

This same problem occurs even on a completely different machine with different hardware than mine. My hardware: Lenovo Ideapad L340-15IRH, i5-9300H, Gpu(s) Gtx 1650, Intel HD 630.

Please help me, what am I doing wrong?

Code to enable transparency, using windows.h inside a C++ function:

HWND hWnd = GetActiveWindow();
res = SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(hWnd, RGB(255, 255, 255), 0, LWA_COLORKEY);

Code which creates the transparent background, in main haxe code:

transparentsquare = new FlxSprite(0, 0).makeGraphic(screenW, screenH, FlxColor.WHITE);
add(transparentsquare);

It doesn't matter if I enable transparency before everything has loaded, I can enable it by pressing a key at any time and it still fails if I enable it after the app has fully loaded. Also, obviously graphics are not drawn in the C++ function but in the haxe code, so I can't use any fancy DirectX APIs and what-not.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 2
    Why are you using GetActiveWindow() to get the HWND? If you don't own the window, you have no business manipulating its transparency outside of its control. – Remy Lebeau Dec 24 '22 at 09:05
  • I'm using GetActiveWindow since that's the only way to get the HWND outside of the main haxe code, the HWND isn't the problem since I can manipulate the entire window to be transparent, but just the colour keying doesn't work on the main monitor – Koharu Xenon Dec 24 '22 at 14:33
  • So `LWA_ALPHA` works but `LWA_COLORKEY` works only on a different monitor – Koharu Xenon Dec 24 '22 at 14:39

0 Answers0