Transparent Backgrounds On Win32

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Transparent Backgrounds On Win32

Postby CdrJameson » Thu Jul 12, 2018 10:41 am

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++
CdrJameson
Newbie
 
Posts: 2
Joined: Thu Jul 12, 2018 9:41 am

Re: Transparent Backgrounds On Win32

Postby ndesktop » Fri Jul 13, 2018 12:25 am

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.
ndesktop
Master
 
Posts: 754
Joined: Thu Dec 03, 2015 10:10 am

Re: Transparent Backgrounds On Win32

Postby ndesktop » Fri Jul 13, 2018 12:27 am

Or SetLayeredWindowAttributes with LWA_COLORKEY. (But without seeing the code I'm just throwing ideas).
ndesktop
Master
 
Posts: 754
Joined: Thu Dec 03, 2015 10:10 am

Re: Transparent Backgrounds On Win32

Postby CdrJameson » Fri Jul 13, 2018 1:50 am

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.
CdrJameson
Newbie
 
Posts: 2
Joined: Thu Jul 12, 2018 9:41 am

Re: Transparent Backgrounds On Win32

Postby yosoymin » Tue Sep 08, 2020 7:02 am

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
yosoymin
Techie
 
Posts: 11
Joined: Mon Mar 02, 2020 1:28 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 40 guests