but counting no of \n will be too costly
if i move the mouse and click at some place the i have to count the number of \n from start of the file
..this will take a long time
Main Topics
Browse All Topicsi am using CRichEditView in my program . i want to show the current line number and coloum number in my status bar as seen in all general editor(like our own vc++ editor).
how can i achieve this.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Can't you get the underlying CRichEditCtrl by calling CRichEditView::GetRichEdit
Ie:
CRichEditCtrl edit = myRichEditView.GetRichEdit
long lineNum = edit.LineFromChar(-1);
According to MSDN, LineFromChar with a -1 as the argument returns the 'current line, that is, the line that contains the caret'...
Ok, given the code I already suggested:
nt idxOfLine = edit.LineIndex(lineNum); // or
int idxOfLine = edit.LineIndex(-1); // line index of current line
long startPos, endPos;
int colPos;
edit.GetSel(&startPos, endPos);
colPos = startPos - idxOfLine;
// colPos should be the column of where the caret is and lineNum should be the line/row where the caret is.
Basic algorithm is to get the index of the first character on that line and get the index of the character you're interested in, subtract the first from the second and that should be column number.
Business Accounts
Answer for Membership
by: cypherljkPosted on 2000-07-27 at 08:50:21ID: 3618819
I saw a suggestion on a similar question where u count the number of '\n' line characters in the RichEdit control and that would give you your line count. Then display the information in your status bar. Don't know about the column tho.
My 2 cents.