Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get the caret's position in a richedit?

How to get the caret's position in a richedit?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
2 Posts 2 Posters 18 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thommi
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • T Thommi

      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

      P Offline
      P Offline
      Peter Zajac
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups