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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Accessing a Specific Text Line Inside CEditView :: MFC

Accessing a Specific Text Line Inside CEditView :: MFC

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasearchitecturehelptutorial
4 Posts 3 Posters 0 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.
  • V Offline
    V Offline
    valikac
    wrote on last edited by
    #1

    Hello. I have a program running under doc/view single doc architecture. When the user opens a text file, the program displays the data from the text file in its original form. Special thanks to Tychom for the key technique. When the program first opens the file, it saves data into a CStringList. However, if the user make changes to one or more lines of text, I have not been able to access the updated text. For example: Original text: --- a b c --- Modified text: --- az b cy0 --- I can get the updated text using GetWindowText(), but that function only returns a specific line parallel to the cursor. What if the user add one or more new lines? I have no way to accessing a specific line. There is a function in CEdit, getline(). The first parameter is the line index. The second is a reference to LPTSTR. I tried to use that function to get a specific line, but the program crashed with an error "bad pointer." LPTSTR text; CEditCtrl::getline(1, text); // this program crashes here every time Is there a way to access a specific line inside CEditView not dependent on where the cursor location? Thanks, Kuphryn

    M J V 3 Replies Last reply
    0
    • V valikac

      Hello. I have a program running under doc/view single doc architecture. When the user opens a text file, the program displays the data from the text file in its original form. Special thanks to Tychom for the key technique. When the program first opens the file, it saves data into a CStringList. However, if the user make changes to one or more lines of text, I have not been able to access the updated text. For example: Original text: --- a b c --- Modified text: --- az b cy0 --- I can get the updated text using GetWindowText(), but that function only returns a specific line parallel to the cursor. What if the user add one or more new lines? I have no way to accessing a specific line. There is a function in CEdit, getline(). The first parameter is the line index. The second is a reference to LPTSTR. I tried to use that function to get a specific line, but the program crashed with an error "bad pointer." LPTSTR text; CEditCtrl::getline(1, text); // this program crashes here every time Is there a way to access a specific line inside CEditView not dependent on where the cursor location? Thanks, Kuphryn

      M Offline
      M Offline
      moliate
      wrote on last edited by
      #2

      The problem is that your string is not initialized. From MSDN (edited for readability): **int CEdit::GetLine( int nIndex, LPTSTR lpszBuffer ) const; int CEdit::GetLine( int nIndex, LPTSTR lpszBuffer, int nMaxLength ) const;** **lpszBuffer** - Points to the buffer that receives a copy of the line. The first word of the buffer must specify the maximum number of bytes that can be copied to the buffer. **nMaxLength** - GetLine places this value in the first word of lpszBuffer before making the call to Windows. Allocate memory for your buffer and make sure the length is inserted, and it should work.... /moliate

      1 Reply Last reply
      0
      • V valikac

        Hello. I have a program running under doc/view single doc architecture. When the user opens a text file, the program displays the data from the text file in its original form. Special thanks to Tychom for the key technique. When the program first opens the file, it saves data into a CStringList. However, if the user make changes to one or more lines of text, I have not been able to access the updated text. For example: Original text: --- a b c --- Modified text: --- az b cy0 --- I can get the updated text using GetWindowText(), but that function only returns a specific line parallel to the cursor. What if the user add one or more new lines? I have no way to accessing a specific line. There is a function in CEdit, getline(). The first parameter is the line index. The second is a reference to LPTSTR. I tried to use that function to get a specific line, but the program crashed with an error "bad pointer." LPTSTR text; CEditCtrl::getline(1, text); // this program crashes here every time Is there a way to access a specific line inside CEditView not dependent on where the cursor location? Thanks, Kuphryn

        J Offline
        J Offline
        jack Mesic
        wrote on last edited by
        #3

        Call UpdateData(TRUE); at first. Regards http://www.ucancode.net/ (Xtreme Diagram++ Library with full MFC Source Code)

        1 Reply Last reply
        0
        • V valikac

          Hello. I have a program running under doc/view single doc architecture. When the user opens a text file, the program displays the data from the text file in its original form. Special thanks to Tychom for the key technique. When the program first opens the file, it saves data into a CStringList. However, if the user make changes to one or more lines of text, I have not been able to access the updated text. For example: Original text: --- a b c --- Modified text: --- az b cy0 --- I can get the updated text using GetWindowText(), but that function only returns a specific line parallel to the cursor. What if the user add one or more new lines? I have no way to accessing a specific line. There is a function in CEdit, getline(). The first parameter is the line index. The second is a reference to LPTSTR. I tried to use that function to get a specific line, but the program crashed with an error "bad pointer." LPTSTR text; CEditCtrl::getline(1, text); // this program crashes here every time Is there a way to access a specific line inside CEditView not dependent on where the cursor location? Thanks, Kuphryn

          V Offline
          V Offline
          valikac
          wrote on last edited by
          #4

          Thanks! I have one question. In the line: // CString myString; CEditCtrl::GetLine(1, myString.GetBuffer(255), 255); Is 255 the maximun number of characters in *that line*? I would like to get everything on that line. In general, is the size (255 in this case) referring to bytes or characters (characters * bytes = maxsize?). Kuphryn

          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