• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1505
  • Last Modified:

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
0
toanphan
Asked:
toanphan
1 Solution
 
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
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
wyy_cqCommented:
CWnd::SetCaretPos(CPoint pt) may work .
you can calculate the width of the string and place the caret to the correct position.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now