Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 1998-03-11
4
713 Views
Last Modified: 2013-11-20
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
Comment
Question by:focht
  • 3
4 Comments
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1316907
CRichEditCtrl::LineIndex( iLine ) gives you the char position of the start of the specified line.

-=- James.

0
 
LVL 4

Expert Comment

by:jtwine100697
ID: 1316908
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
 
LVL 1

Author Comment

by:focht
ID: 1316909
  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
 
LVL 4

Accepted Solution

by:
jtwine100697 earned 50 total points
ID: 1316910
  Note that if you are trying to create some kind of editor, this will not "expand" tabs correctly...

-=- James.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question