EN_SETFOCUS 或 WM_SETFOCUS 上的 SetSel 不起作用
我在 Winapi/MFC 中遇到了下一个神秘的事情,我有一个编辑框,我必须在 Tab、Lclick、Rclick、Mclick 等上选择其中的内容。
最明显的路径是处理 SETFOCUS 消息并调用 SetSel(0, -1),这应该选择所有文本。但这不起作用!
怎么了?我尝试谷歌搜索,每个人似乎都在父窗口中覆盖Lclilks或处理SetSel,但从封装的角度来看这是错误的,而且多次点击(用户想要在文本中间插入一些东西)也会中断,等等。
为什么我的方法不起作用,我尝试了 10 种不同的方法,尝试捕获所有可能的焦点消息,在 MSDN 上查找信息,但没有任何效果按预期进行。
另外,我需要重新创建焦点上的卡雷,这似乎也不起作用。
SETFOCUS 消息被困住了。如果我添加 __asm int 3 ,它每次都会中断。
看起来是创建的 carret 和 setsel 被吞没了。
I've ran into next mystic thing in Winapi/MFC, I have an edit box, contents of which I have to select on Tab, Lclick, Rclick, Mclick and so on.
The sort of obvious path is to handle the SETFOCUS message and call SetSel(0, -1), which should select all text. But it doesn't work!
What's wrong? I tried googling, everyone seems to override Lclilks or handle SetSel in parent windows, but this is wrong from encapsulation point of view, also multiple clicks (user wants to insert something in the middle of the text) will break, and so on.
Why isn't my approach working, I tried like 10 different ways, tried to trap all possible focus messages, looked up info on MSDN, but nothing works as expected.
Also, I need to recreate the carret on focus, which also doesn't seem to work.
SETFOCUS message gets trapped alright. If I add __asm int 3
, it breaks every time.
It's the create carret and setsel that gets swallowed it seems.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在处理
WM_SETFOCUS
时发布编辑EM_SETSEL
。鼠标输入可能是在焦点切换后处理的。或者发布用户消息并在接收时创建插入符号,然后进行选择。Post the edit an
EM_SETSEL
while handlingWM_SETFOCUS
. The mouse input is probably processed after the focus switches. Or post a user message and on receiving create the caret and then do the selection.