通过插入符看到的 Delphi Focus 问题

发布于 2024-08-23 14:07:06 字数 389 浏览 3 评论 0原文

我在 Delphi 中编写了一个高级文本编辑器组件(固定宽度、语法突出显示等),使用 Windows API 与 TCanvas 元素相结合,它工作得很好,除了一件事:如果我将焦点设置到也显示插入符号的同一应用程序,例如 TEdit,从我的编辑器组件中窃取焦点,新编辑器(例如 TEdit)的插入符号不会显示;相反,插入符号在我的编辑器组件中移动!例如,如果我在新编辑器 (TEdit) 中编写一个字符,它将按预期显示,并且插入符号将在我的组件中移动到右侧。什么会导致这种情况?我怀疑 Win API 对键盘焦点的处理和 VCL 处理之间存在一些冲突。在我的编辑器组件中,我使用 CreateCaret 来响应 WM_SETFOCUS,使用 DestroyCaret 来响应 WM_KILLFOCUS。显然,只有当新的编辑控件位于新的模态窗口中时,才会出现该问题。

I have written an advanced text editor component (fixed-width, syntax highlighting, etc.) in Delphi, using Windows API combined with the TCanvas element, and it works great, except for one thing: If I set focus to another control inside the same application that displays a caret as well, such as a TEdit, stealing focus from my editor component, the caret of the new editor (such as TEdit) is not shown; instead the caret moves in my editor component! For example, if I write a character in the new editor (TEdit), it will show up as expected, and the caret will move to the right in my component. What can cause this? I suspect there is some conflict between Win API's handling of keyboard focus and the VCL handling. In my editor component, I use CreateCaret in response to WM_SETFOCUS and DestroyCaret in response to WM_KILLFOCUS. Apparently the problem only occurs if the new edit control is in a new, modal, window.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

Bonjour°[大白 2024-08-30 14:07:06

我在组件的代码中发现了一个小错误。我很抱歉。

I found a trivial bug in the component's code. My apologies.

人海汹涌 2024-08-30 14:07:06

我的第一个想法是您没有收到 WM_KILLFOCUS 消息。我会构建一个诊断来告诉你它是否正在发生。

倾向于使用调试器来解决此类问题,我发现在尝试诊断此类交互时,修改标题等操作效果更好。

My first thought would be that you're not getting the WM_KILLFOCUS message. I would construct a diagnostic to tell you whether it's happening or not.

I am NOT inclined to use a debugger for this sort of problem, I find doing things like modifying the title works better when trying to diagnose interactions like this.

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