Windows 静态控制如何阻止输入焦点
我们知道Windows中的静态控制不接收输入焦点。但由于Windows中的静态控制只是一个子窗口,根据我目前的理解,任何窗口在我们点击它时都应该获得输入焦点。那么Static控件是如何实现这种拒绝输入焦点的效果的呢?我怀疑它在 WM_SETFOCUS 处理程序中进行了特殊处理,将输入焦点生成到其父窗口。然而,我做了一些测试,似乎子窗口实际上根本没有收到任何 WM_SETFOCUS ,即 Windows 从未真正尝试将输入焦点赋予静态控件。
我读过关于输入焦点的msdn,但没有与Windows如何为静态控制分配焦点相关的内容。谁能解释如何使静态控制没有输入焦点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
静态控件从其 返回
HTTRANSPARENT
WM_NCHITTEST
处理程序。这会导致单击直接转到底层窗口(即父窗口)。WM_MOUSEACTIVATE
和WM_*BUTTONCLICK
以及其他魔法最终会导致激活和SetFocus
。The static control returns
HTTRANSPARENT
from itsWM_NCHITTEST
handler. That causes the click to go directly to the underlying window (which is the parent). TheWM_MOUSEACTIVATE
andWM_*BUTTONCLICK
and other magic eventually leads to an activation andSetFocus
.