如何在CEdit控件中预留插入位置? [英] How do I reserve caret position in CEdit control?

查看:113
本文介绍了如何在CEdit控件中预留插入位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MFC中编程一个应用程序(不要问),我有一个CEdit框保存一个数字。当编辑该数字时,我想对更改执行操作,然后替换在我对更改采取行动之前的插入符号 - 如果用户刚好在之前。在35.40,我想它仍然放在点之前,如果他们改变为345.40。我目前正在捕获CHANGE消息,但是可以切换到其他(更新?)。

I'm programming an application in MFC (don't ask) and I have a CEdit box that holds a number. When that number is edited, I would like to act on the change, and then replace the caret where it was before I acted on the change - if the user was just before the "." in "35.40", I would like it to still be placed before the dot if they change it to "345.40". I'm currently catching the CHANGE message, but that can be switched to something else (UPDATE?). How can I accomplish this?

推荐答案

在更改之前使用GetSel()函数来存储游标的位置,然后使用SelSel()将其设置回来。您可以使用这些函数获取/设置插入符的位置,而不仅仅是获取/设置用户所做的选择。

Use the GetSel() function before your change to store the location of the cursor, then use SelSel() to set it back. You can use these functions to get/set the location of the caret, not just to get/set the selection the user has made.

这篇关于如何在CEdit控件中预留插入位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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