views:

19

answers:

1

We know that Static Control in Windows does not receive input focus. But since Static Control in Windows is just a child window, according to what I understand so far, any window should be given input focus when we click on it. So how does Static control achieve this effect of rejecting input focus? I suspect it has special processing in its WM_SETFOCUS handler that yields the input focus to its parent window. However, I've done some tests and it seems that the child window really does not receipt any WM_SETFOCUS at all i.e. Windows never really tried to give input focus to the static control at all.

I've read the msdn on input focus and there is nothing related to how Windows allocate focus for static control. Can anyone explain how Static Control is made not to have input focus?

+2  A: 

The static control returns HTTRANSPARENT from its WM_NCHITTEST handler. That causes the click to go directly to the underlying window (which is the parent). The WM_MOUSEACTIVATE and WM_*BUTTONCLICK and other magic eventually leads to an activation and SetFocus.

Adrian McCarthy