How to position the caret in CEdit

When I select the entire text in an edit box by calling CEdit::SetSel, the caret is automatically moved to the end of the selection.  However, I want to be able to keep the caret at the beginning of the text when it's highlighted, not at the end of it.  So the question is, is there a way to move the caret to position 0 in a CEdit when the text highlighted?
Toan Phan
toanphanAsked:
Who is Participating?
 
wyy_cqConnect With a Mentor Commented:
CWnd::SetCaretPos(CPoint pt) may work .
you can calculate the width of the string and place the caret to the correct position.
0
 
ddeboskeyCommented:
A call to SetCaretPos should be able to move the caret after the call to SetSel.  Since SetCaretPos takes an X and Y coordinate, you may need to call CEdit::PosFromChar() in order to obtain the correct coordinates for the right character index.  

I hope this helps.
Dave.
0
 
toanphanAuthor Commented:
The caret is a shared resource, and a call to SetCaretPos for CEdit does not have any effect.  Any examples how to do this would really help.
Thanks.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
toanphanAuthor Commented:
The caret is a shared resource, and a call to SetCaretPos for CEdit does not have any effect.  Any examples how to do this would really help.
Thanks.
0
 
BridgeCommented:
Use CEdit::SetSel(...)
0
 
BridgeCommented:
Sorry, didnt read the question fully. The answer is not there isnt.
0
 
toanphanAuthor Commented:
Bridge did not give the answer as he misread the question.  Any other answers?
0
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.

All Courses

From novice to tech pro — start learning today.