How to get the caret's position in a richedit?
-
Hi all, I am writing a MDI application, which views are derivated by CRichEditView. In the status bar, I want to display the current position of the caret. The line number is easy to get, just call GetRichEditCtrl().LineFromChar(-1), but how to determine the column? Thanks in advance, Thömmi
-
Hi all, I am writing a MDI application, which views are derivated by CRichEditView. In the status bar, I want to display the current position of the caret. The line number is easy to get, just call GetRichEditCtrl().LineFromChar(-1), but how to determine the column? Thanks in advance, Thömmi
Thömmi, You are actualy very close to the solution to this problem. To get the caret position within current line you will have to look at two CRichEditCtrl member functions. GetSel - if you are not handling the 'EN_SELCHANGE' notification than use this function to get current position of the caret. Vales returned contain character position from the beginning of the rich edit string. Use the LineIndex function to get total number of characters before current line. By subtracting chars before line from the caret position you will get column index in current line. void CRichEditTestDlg::OnSelchangeRichedit(NMHDR* pNMHDR, LRESULT* pResult) { SELCHANGE *pSelChange = reinterpret_cast(pNMHDR); CString tempStr; tempStr.Format( "ln: %d, col: %d", m_richEdit.LineFromChar( -1 ), pSelChange->chrg.cpMin - m_richEdit.LineIndex( -1 )); SetDlgItemText( IDC_POS, tempStr ); *pResult = 0; } Peter Zajac Dundas Software ================== The original message was: Hi all,
I am writing a MDI application, which views are derivated
by CRichEditView. In the status bar, I want to display the
current position of the caret. The line number is easy to get,
just call GetRichEditCtrl().LineFromChar(-1), but how to determine the column?Thanks in advance,
Thömmi