分层的窗口,UpdateLayeredWindow,alpha混合和鼠标事件鼠标、窗口、事件、alpha

2023-09-04 03:58:38 作者:人间风雪客

在Windows窗体和C#中,我使用的WS_EX_LAYERED风格的一种形式,并调用的 UpdateLayeredWindow 的背景设置为一个图像是透明/ alpha混合:

In Windows Forms and C#, I'm using a form with the WS_EX_LAYERED style, and calling UpdateLayeredWindow to set the background to an image that is transparent/alpha blending:

NativeMethods.BLENDFUNCTION blend = new NativeMethods.BLENDFUNCTION();
blend.BlendOp = NativeMethods.AC_SRC_OVER;
blend.BlendFlags = 0;
blend.SourceConstantAlpha = 255;
blend.AlphaFormat = NativeMethods.AC_SRC_ALPHA;

NativeMethods.UpdateLayeredWindow(form.Handle, screenDc, ref topPos, ref size, 
    memDc, ref pointSource, 0, ref blend, NativeMethods.ULW_ALPHA);

在其中图像是透明的形式的区域中,所述形式不接收鼠标事件。他们去的是形式下的窗口。

On the regions of the form where the image is transparent, the form does not receive mouse events. They go to the window that is under the form.

有一个窗口样式或可设置为启用的形式来接收鼠标事件(鼠标移动,按下鼠标等),在其整个表面的选择吗?

Is there a window style or an option that can be set to enable the form to receive mouse events (mouse move, mouse down, etc.) on its entire surface?

推荐答案

从的分层窗口

分层窗口的命中测试是基于窗口的形状和透明度。这意味着窗口的所有在区域颜色键控或其alpha值是零会让鼠标消息通过。 如果分层窗口具有WS_EX_TRANSPARENT扩展窗口风格,层状窗口的形状将被忽略,鼠标事件将被传递到其它窗口分层窗口的下面。

Hit testing of a layered window is based on the shape and transparency of the window. This means that the areas of the window that are color-keyed or whose alpha value is zero will let the mouse messages through. If the layered window has the WS_EX_TRANSPARENT extended window style, the shape of the layered window will be ignored and the mouse events will be passed to the other windows underneath the layered window.

我会尝试rmeoving的WS_EX_TRANSPARENT风格

I would try rmeoving that WS_EX_TRANSPARENT style