Q:

Best way to make mouse clicks not pass through disabled components?

I'm using common windows controls such as "BUTTON" and "EDIT" for my application. There are cases where I want to disable components, so I use the EnableWindow function to make the components look disabled and not receive events.
The problem is however that the disabled component doesn't just block the mouse click events - instead it passes them to the components below it. Is there any way to prevent mouse click events from passing through disabled components? Or alternativly, an easy way to check for this case and discard these events?
I thought of making transparent windows on top, but that sounds somehow too complex for something which seems so trivial. I also though about hit testing of the mouse coordinates with the children of each container before accepting the event.
Is there any better way? I already have a custom area in my WndProc (I subclassed the button class) to catch the mouse button events if it helps.
Thanks in advance!

A:

From the EnableWindow documentation:

When input is disabled, the window does not receive input such as mouse clicks and key presses.

So by definition, when the window is disabled, it doesn't receive mouse clicks. What you're seeing is the expected, intended behavior, and I don't think there's any way to change it.
I'm not sure why you're trying to train your users to click on something that's disabled (every other Windows app will just ignore those clicks, so you're training your users to be confused by either your app or by every other app on the planet), but if you really want to support this, the simplest way is probably to put the button inside a panel that's exactly the same size as the button.

