I have this very strange problem. I write something in a rich edit control 2.0. I save it to a .rtf file. The I open the file, but the problem is that the text in the rich edit control appears with some other strange characters. If I open the file using Microsoft Word, then the text is OK.
for example:
I save the folowing text:
this is just a test
then when I open the file in the rich edit the text appears as follows:
this is just a test췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍췍
before of "this" it also puts me a small square which I am unable to paste here.
this is the code for saving the file:
void CProofingToolsAppDlg::OnFisierSalveaza()
{
CFileDialog fdlg(false, L"rtf", NULL, OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
L"Rich text files (*.rtf)|*.rtf|All Files (*.*)|*.*||", NULL, NULL);
if(fdlg.DoModal() == IDOK)
{
CString FileName = fdlg.GetPathName();
FILE* fisier;
fisier=_wfopen(FileName,L"w, ccs=UTF-16LE");
CString cs;
//here i get the text from the rich edit
m_rich.GetWindowTextW(cs);
//and write it to file
fwrite(cs.GetBuffer(),sizeof(wchar_t), wcslen(cs.GetBuffer()),fisier);
fclose(fisier);
}
}
void CProofingToolsAppDlg::OnFisierDeschide()
{
CFileDialog fdlg(true, L"rtf", NULL, OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST,
L"Rich text files (*.rtf)|*.rtf|All Files (*.*)|*.*||", NULL, NULL);
if(fdlg.DoModal() == IDOK)
{
CString FileName = fdlg.GetPathName();
int length;
wchar_t* buffer;
FILE* fisier;
fisier=_wfopen(FileName,L"r, ccs=UTF-16LE");
fseek(fisier,0,SEEK_END);
length=ftell(fisier);
fseek (fisier, 0, SEEK_SET);
// get length of file:
// allocate memory:
buffer = new wchar_t [length+1];
fread(buffer, sizeof(wchar_t),length,fisier);
buffer[length] = L'\0';
fclose(fisier);
CString c1(buffer);
//here I write the file to the rich edit
m_rich.SetWindowTextW(c1.GetBuffer());
delete[] buffer;
}
UpdateData(false);
}
instead of UTF-16LE I tried all the other encodings from http://msdn.microsof...b(v=vs.80).aspx but for no use
To put it simple: the saving works, but the opening does not.
This post has been edited by livium: 31 May 2012 - 11:12 PM

New Topic/Question
Reply



MultiQuote





|