5

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?

Nakilon
  • 34,866
  • 14
  • 107
  • 142
Omer
  • 661
  • 7
  • 21
  • Do you need this general capability at all times or just at certain times (e.g., when your window is the active window). If the latter, you can capture the mouse. – Adrian McCarthy May 18 '11 at 23:57
  • Another problem with a hook is that you have to be very careful your window is on top so that you don't steal clicks on other windows. Perhaps it would help if you gave more information about what you're trying to achieve. – Adrian McCarthy May 18 '11 at 23:58
  • I'll explain it better, I'm drawing PNG icons and trying to detect whether the mouse is hovering those items. Now most of the icons have zero alpha regions and when I'm hovering them I'm not getting the WM_MOUSEMOVE event because their container windows is transparent. – Omer May 19 '11 at 10:43

1 Answers1

1

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

Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167