Edit Control Read


Click here to change the theme.

The following is an example of reading a file into a MultiLine Edit Control. In this example, m_FileData is a CString type member variable for the control. This example would be appropriate for a dialog's OnInitDialog.

	CFileException FileExc;
	CFile Inputfile;
	DWORD FileSize;
CDialog::OnInitDialog;
if (!Inputfile.Open("C:\\CONFIG.SYS", CFile::modeRead, &FileExc)) {
	FileExc.ReportError();
	return TRUE;
	}
FileSize = Inputfile.GetLength();
FileSize = __min(FileSize, INT_MAX);
FileSize = Inputfile.Read(m_FileData.GetBuffer(FileSize), FileSize);
m_FileData.ReleaseBuffer(FileSize);
Inputfile.Close();
UpdateData(FALSE);

Maximum Sizes

The maximum size of a CString is INT_MAX (about 2 GB) characters. See Data Type Constants for a description of INT_MAX. The maximum size of an edit control is documented in the EM_SETLIMITTEXT message. The default text limit size for a CEditView is 1,048,575, which can be changed by CEdit::SetLimitText, but SetLimitText cannot set a limit greater than the limits described in the EM_SETLIMITTEXT message.