views:

459

answers:

2

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?

A: 

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.

Roel
A: 

Could you explain the reason why you would want to change the behavior of the CEdit box? As a user I would have a problem with the caret being changed every time I enter some character. Or is it what you would like to prevent if you change that value programmatically?

Andre
As a user, I would expect the caret to stay in the same place. If you change the value of the CEdit with .SetWindowTextA() for example, the caret gets moved to the front of the box. This is a way to prevent that.
jamuraa