通过插入符看到的 Delphi Focus 问题
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在组件的代码中发现了一个小错误。我很抱歉。
I found a trivial bug in the component's code. My apologies.
我的第一个想法是您没有收到 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.