使用 WM_SETTEXT 替换窗口内容,同时保持窗口滚动位置 [英] Use WM_SETTEXT to replace contents of window whilst maintaining window scroll position

查看:29
本文介绍了使用 WM_SETTEXT 替换窗口内容,同时保持窗口滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个将 RTF 文本发送到第三方窗口的应用程序.它基本上在原始的第三方 IDE 中提供自动更正功能.

I'm building an application that sends RTF text to a third-party window. It basically provides auto-correct functionality within a primitive third-party IDE.

我可以设置此窗口的内容(即更正后的代码),但这样做会将窗口的滚动位置设置为顶部.这很烦人,因为用户必须向下滚动到自动更正开始之前的位置.

I can set the contents of this window (i.e. the corrected code), but doing so sets the window's scroll position to the top. This is very annoying because then the user has to scroll down to where they were before the autocorrect kicked in.

我可以将光标设置到正确的位置(在页面下方),但这并不能阻止窗口滚动到顶部.

I can set the cursor to the correct position (down on the page), but this doesn't prevent the window from scrolling to the top.

有什么建议吗?

推荐答案

WM_SETTEXT 是替换一小部分文本时使用的错误消息.您使用 WM_SETTEXT 来设置控件的整个文本内容.

WM_SETTEXT is the wrong message to use when replacing a small portion of the text. You use WM_SETTEXT to set the entire text content of the control.

您要的是选择需要更正的单词.为此使用 EM_SETSEL.然后使用 EM_REPLACESEL 将文本替换为更正后的版本.我希望这也会有解决不需要的滚动问题的快乐效果.

What you want is to select the word that needs to be corrected. Use EM_SETSEL for that. And then use EM_REPLACESEL to replace the text with the corrected version. I expect that will also have the happy effect of fixing the problem of unwanted scrolling.

这篇关于使用 WM_SETTEXT 替换窗口内容,同时保持窗口滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆