Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 735
  • Last Modified:

CRichEditCtrl: get current caret pos. as offset to line-begin

I need to determine the position of the caret (after character input) relative to the begin of the current line.
In a CRichEditCtrl i can get the current line via "LineFromChar(-1)". There is no class member function to determine the current caret pos relative to the line-beginning. Do i have to trap On_Char() and count the chars input for each line to get current caret pos or is there a
better solution ?
0
focht
Asked:
focht
  • 3
1 Solution
 
jtwine100697Commented:
CRichEditCtrl::LineIndex( iLine ) gives you the char position of the start of the specified line.

-=- James.

0
 
jtwine100697Commented:
No, i don't want an offset relative to the beginning of the control (1.st line, 1.st char) (that is all that LineIndex(i) does). I need the character offset relative to the beginning of the current line (line x: character 1 = offset 0 ...).
Ex: caret at pos 10 in line 5 = offset 10.
 
0
 
fochtAuthor Commented:
  You use the value returned from LineIndex( iLine ) with the current caret position.  That gives you the char position of the current line.

   GetSel( iSelStart, iSelEnd )
   iColumn = ( iSelEnd - LineIndex( -1 ) );

   See?

-=- James.

0
 
jtwine100697Commented:
  Note that if you are trying to create some kind of editor, this will not "expand" tabs correctly...

-=- James.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

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