Page 1 of 1

Transparent Backgrounds On Win32

PostPosted: Thu Jul 12, 2018 10:41 am
by CdrJameson
Hello,

I have a multi-platform application with an HTML/JS webview for a GUI, displayed over a natively rendered game screen.
Recently the UI designers changed the pause screen so that instead of covering the entire screen it let you see the paused game behind by using a semi-transparent background to the webview.
This has worked fine on most platforms (Android, iOS, Windows UWP) but not on win32 where CEF provides the webview.

Having looked around the topic I am beginning to suspect that this relatively cosmetic change is going to need me to completely re-architect my application display to use the slower off-screen rendering on win32.
Is it really the case that there is no simpler way to support a transparent background for a CEF window on win32?
Here's hoping there is.

Details:

CEF version is 3.3239.1723.g071d1c1

The HTML has bgcolor="transparent" set.
The CefBrowserSettings.background_color is set to 0x00000000
The CefSettings.background_color is set to 0x00000000 as well
CefWindowInfo doesn't have the very handy sounding SetTransparentPainting() method any more

The CEF window is currently SetAsChild() for my main game window, which can be windowed, borderless windowed or true fullscreen.
Tried SetAsPopup() for a change, and it also doesn't do transparency.

The main window is created Windowed by default with
style: WS_CLIPSIBLINGS | WS_CLIPCHILDREN |= WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_THICKFRAME;
extended style: WS_EX_APPWINDOW
(via GLFW)

The child (CEF) window is SetAsChild() which sets:
style: WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_TABSTOP | WS_VISIBLE

I tried adding WS_EX_LAYERED to the CEF window, but that didn't make any difference.

I'm using C/C++

Re: Transparent Backgrounds On Win32

PostPosted: Fri Jul 13, 2018 12:25 am
by ndesktop
Looks like SetWindowRgn might help in your case. Compute main (full) rect, then the hole rect, diff, and set the window region with a hole inside.
Not sure if I put everything together correctly, but that might be a start.

Re: Transparent Backgrounds On Win32

PostPosted: Fri Jul 13, 2018 12:27 am
by ndesktop
Or SetLayeredWindowAttributes with LWA_COLORKEY. (But without seeing the code I'm just throwing ideas).

Re: Transparent Backgrounds On Win32

PostPosted: Fri Jul 13, 2018 1:50 am
by CdrJameson
Well, that's two things I haven't tried yet and can have a look at, so thanks for the suggestions!

I've also considered taking a copy of the native screen and passing that back to the browser window when it's shown to use as a background image.
Nothing will be happening in the background window while the browser is showing, and this avoids needing transparency altogether and works on all platforms.

It'd be really nice if I was just overlooking some obvious setting that makes the transparency actually be transparent though.

Re: Transparent Backgrounds On Win32

PostPosted: Tue Sep 08, 2020 7:02 am
by yosoymin
I've found a way this is possible using views framework and a simple modification in CEF code. This is working in Windows and Linux. More info in this thread: https://www.magpcss.org/ceforum/viewtop ... =8&t=17421