Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to intercept mouse events of a transparent window?

I have a transparent window (created with WS_EX_LAYERED) and I'd like to receive mouse events of the zero-alpha regions.
As far as I know, I could:

1) Use mouse hook
2) Paint the background with almost completely transparent color (that has an opacity of 1)

However, the first solution is time consuming and the 2nd one will slow my rendering time as my window is stretched almost all over the desktop and most of the pixels are completely transparent at the moment.

Is there another way receiving those mouse events?

like image 845
Omer Avatar asked Nov 13 '22 23:11

Omer


1 Answers

According to MSDN:

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. However, 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 other windows underneath the layered window.

However, in a new thread you could get continuously the coordinates of the mouse with GetCursorPos and if the position is inside one of your icons (regardless, that it's over a zero alpha pixel inside the icon) you handle it. Not too much better than the hook

like image 158
Ferenc Deak Avatar answered Nov 16 '22 23:11

Ferenc Deak