Create custom transparent management

I am trying to create a custom control that displays a bitmap with a pixel alphabet (as some of you already know about other issues).

Right now I am using a custom control in the resource editor and I am attaching it to a class derived from CWnd. When I register my custom class, I set the hbrBackground of the WNDCLASS structure to NULL_BRUSH to achieve the transparency of the control.

In the OnPaint of the control, I use AlphaBlend to draw an alpha bit per pixel bitmap.

This works very well, but I have two problems:

  • I want to change the displayed bitmap when the mouse is over the control. Because the control is transparent, areas that are one bitmap that does not overlap with another bitmap are not erased. How to erase the background when changing the image?

  • The second problem is related to two overlapping controls. My control is colored over another control that has a gradient (actually located inside another control). The problem is that if I set my control earlier in z-order, other controls overlap my control, and mine does not appear. If I put another control in z-order, I cannot get a mouse message in my control.

Maybe I'm doing something wrong, or I'm wrong in how I try to exercise my control. Any help would be appreciated.

Thanks,

Javier

+5
source share
1 answer

I will risk.: -)

This should give you everything you need to accomplish what I think you need.

General solution for transparent controls

Regarding Z-order issues, z-order does not affect message priority. You will need to publish the code so that we can determine what is going on there.

+1
source

All Articles