Transparent top-level windows

I would like to create a top-level window (i.e. not WS_CHILD) with transparency. However, I do not want it to be a simple mask, where the given pixel is either completely transparent or completely opaque. And I don’t want it to be so that the whole window has an alpha level. Rather, I want the window to be essentially completely transparent, with a bitmap drawn on it with an alpha channel, so that the bitmap mixes with any windows that may be behind it. A picture, say, of a solar charge, where the image of its own alpha mixture is from opaque to completely transparent outward from the center.

I found two methods that come close to what I want to do, but not quite. Using regions, I can cut out a fully transparent section. Using layered windows, I can also do something like this (or even make the whole window transparent, but that's not what I want at all). I looked at other styles, such as WS_EX_TRANSPARENT and WS_EX_COMPOSITE, but to no avail.

I can get this effect to work fine on child windows, as they mix with the parent windows in the parent region. The fact that it works similarly for top-level windows continues to elude me.

I know that this can be done, because people assured me that they saw it in other programs. I feel like I just don't quite understand something simple here about painting windows.

+3
source share
2 answers

Layered windows ( WS_EX_LAYERED) should do the job, bearing in mind that you must use a UpdateLayeredWindow()somewhat unusual bitmap image format (32-bit, pre-multiplied alpha) to specify alpha values ​​in pixels ( SetLayeredWindowAttributes()allows you to specify only one alpha value for whole window or color key).

You say you already tried it - what problems did you experience?

+2
source

The only way I know is to get the alpha pixel in the window is UpdateLayeredWindow ().
Check out this MSDN link: http://msdn.microsoft.com/en-us/library/ms997507.aspx

, UpdateLayeredWindow WM_PAINT , , , . UpdateLayeredWindow , Win32.

, , .

+1

Source: https://habr.com/ru/post/1703312/


All Articles