How to control cursor and backspac's position in edit control?

I have an edit control, how I set the cursor to the position that I want within this control, for example, after I type two characters, I don't want the cursor stay at third position instead I want the cursor jump to the fouth position. The same thing for "back space" key, if there is a text in control, and I used this key to delete from the end of text, but I don't want to delete a special character in this text, how to let "back space" jump over from this character to next character.

Thanks.
Hanqian
 
HanqianAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
CEdit::SetSel function with equal values of nStartChar and nEndChar parameters sets cursor to specified position. For example:

pEdit->SetSel(1, 1);

sets cursor after first character in the control.
0
HanqianAuthor Commented:
I have tried it, it doesn't work. After I type two chars. I use pEdit->SetSel(4, 4), it doesn't go to the position 4.

Hanqian
0
AndyAinscowFreelance programmer / ConsultantCommented:
I assume your control is empty when you start typing.
You would need to add the third (space) character yourself then position at the end (4th) position.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

HanqianAuthor Commented:
I did add "/" at third position.

Hanqian
0
AlexFMCommented:
If edit control has 3 characters, you can write:

pEdit->SetSel(3, 3);

4 is still out of range.
0
HanqianAuthor Commented:
That means that we can't use SetSel() to set the cursor at the blank position of the edit control.

Hanqian
0
AndyAinscowFreelance programmer / ConsultantCommented:
Set it at the end of the text as I said earlier.  As Alex says if you only have 3 chars then the fourth doesn't exist.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.