Solved

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

Posted on 1998-03-11
4
721 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
[X]
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
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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