CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Posts
    72

    Displaying .txt file in Edit Box Control

    How can I display the contents of an .txt file in a EditBox called m_Info?


  2. #2
    Join Date
    May 1999
    Location
    Republic of Korea
    Posts
    74

    Re: Displaying .txt file in Edit Box Control

    Did you associate the edit box to a member variable called m_Info?
    Then you can set the string to m_Info and call UpdateData function as follows.
    m_Info = "String you read from txt file";
    UpdateData(FALSE);

    Otherwise, you can use the following method.
    GetDlgItem(ID_FOR_EDITBOX)->SetWindowText("String you read from txt file");

    If the txt file has multiple lines, you must set multiline checkbox at the property page of the editbox.



  3. #3
    Join Date
    Apr 1999
    Posts
    72

    Re: Displaying .txt file in Edit Box Control

    That will just set the text in the editbox! I have a file called Info.txt I want to display all the text from that file in m_Info EditBox Control. Please help with this!

    Thanks,
    Nathan Strandberg


  4. #4
    Join Date
    May 1999
    Posts
    44

    Re: Displaying .txt file in Edit Box Control

    Hey.... just copy the contents of the file on to a string.
    Open the .txt file, read the contents using fgtes or whatever, and add this to the CString variable.
    Then use this string to put onto the edit box.

    Need anymore help???


  5. #5
    Join Date
    May 1999
    Location
    Oregon, USA
    Posts
    302

    Re: Displaying .txt file in Edit Box Control

    Here is pseudo-code to do this :

    Open the file // call CreateFile with GENERIC_READ access.
    Get the file's size // call GetFileSize
    Allocate a buffer for the file
    Read entire file into the buffer // call ReadFile and pass the size of the file
    // and the pointer buffer as arguments - one call can do this.
    Set control's text // call SetDlgItemText and pass the buffer as an arg.
    Release the buffer
    Close the file

    I'll leave the details of implementation as an exercise for the reader.
    Be aware that there is a limit to the amount of text an edit control can handle.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured