How to write the Multi Text line in the File in MFC programming ?

I'm a newbie in MFC programming. I'm trying to read the Edit Control text and Write into the File.So the Edit control has multi line text when i write the text into the file only first line is written .


CString EC_data;
CWnd* InEC = GetDlgItem(IDC_EDIT1);
InEC->GetWindowText(EC_data);

// After the GetwindowText() ,EC_Data have all the Multi line Text .......


CFile DataFile(Filepath,CFile::modeCreate|CFile::modeWrite);
DataFile.Write(EC_data,EC_data.GetLength());
Last edited on
I also had my problems. This works for me:
1
2
3
4
5
6
7
8
9
10
  CString Filepath = _T ("Test.txt");
  CEdit *pEdit = (CEdit *)GetDlgItem (IDC_EDIT1);
  ASSERT (pEdit != NULL);
  int len = pEdit->GetWindowTextLength ();
  TCHAR *pBuffer = new TCHAR[len+1];
  pEdit->GetWindowText (pBuffer, len+1);
  CFile DataFile (Filepath, CFile::modeCreate | CFile::modeWrite);
  DataFile.Write (pBuffer, len);

  delete [] pBuffer;


Make sure that you use the Multibyte Character Set and that you use "\r\n" for the line breaks.

Here are some tutorials:
http://www.codeproject.com/search.aspx?q=CEDIT&x=0&y=0&sbo=kw
Topic archived. No new replies allowed.