TechAurelian
TechAurelian

Reputation: 5811

Layered windows, UpdateLayeredWindow, alpha blending and mouse events

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?

Upvotes: 1

Views: 2615

Answers (1)

Alan
Alan

Reputation: 7951

From Layered Windows

Hit Testing

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.

I would try rmeoving that WS_EX_TRANSPARENT style

Upvotes: 1

Related Questions