Thread: Accessing a Specific Text Line Inside CEditView :: MFC

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    Accessing a Specific Text Line Inside CEditView :: MFC

    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

  2. #2
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Why not read the whole thing in and parse at '\n'?

    Or you could use a listbox.. which would make things much simpler.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks.

    The problem was I did not inititalize the variable text before passing it to GetLine(1, text).

    Here is a solution:

    char text[256];
    CEditCtrl::GetLine(1, text, 256);

    GetLine(...) needs the size of the buffer.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. reading a text file printing line number
    By bazzano in forum C Programming
    Replies: 4
    Last Post: 09-16-2005, 10:31 AM
  2. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  3. Validating the contents of a char buffer
    By mattz in forum C Programming
    Replies: 3
    Last Post: 12-09-2001, 06:21 PM
  4. inputting line of text vs. integers in STACK
    By sballew in forum C Programming
    Replies: 17
    Last Post: 11-27-2001, 11:23 PM
  5. text line termination
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 09-09-2001, 04:39 AM