EN_SETFOCUS 或 WM_SETFOCUS 上的 SetSel 不起作用

发布于 2024-10-09 06:10:55 字数 446 浏览 0 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆悲凉 2024-10-16 06:10:55

在处理 WM_SETFOCUS 时发布编辑 EM_SETSEL。鼠标输入可能是在焦点切换后处理的。或者发布用户消息并在接收时创建插入符号,然后进行选择。

Post the edit an EM_SETSEL while handling WM_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文