How can I display the contents of an .txt file in a EditBox called m_Info?
Printable View
How can I display the contents of an .txt file in a EditBox called m_Info?
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.
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
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???
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.