Click to See Complete Forum and Search --> : Displaying .txt file in Edit Box Control


Nathan Strandberg
June 1st, 1999, 05:17 PM
How can I display the contents of an .txt file in a EditBox called m_Info?

Jaeyeon Lee
June 1st, 1999, 08:31 PM
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.

Nathan Strandberg
June 1st, 1999, 11:05 PM
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

Pallavi
June 2nd, 1999, 12:50 AM
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???

Gomez Addams
June 2nd, 1999, 02:34 PM
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.