Discussion:
How to serialize a text in CRichEditCtrl?
(too old to reply)
workaholic
2007-01-05 11:15:12 UTC
Permalink
I want my text written in CRichEditCtrl to output as plain text, and I
did this:
//in View:
void CLEView::OnFormatConvert()
{
CRichEditCtrl *pCtrl = &this->GetRichEditCtrl();
pCtrl->SetSel(0,-1);

this->GetDocument()->m_text = pCtrl->GetSelText();
}
//in Document:
void CLispEditorDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar<<m_text;// TODO: add storing code here
}
else
{
ar>>m_text;// TODO: add loading code here
}


}
But it turns out to be a complex text with lengthy ugly characters and
the useful part only exists in the rear of the file, why?
Thanks in advance!
David Lowndes
2007-01-05 11:29:44 UTC
Permalink
Post by workaholic
I want my text written in CRichEditCtrl to output as plain text, and I
...
But it turns out to be a complex text with lengthy ugly characters and
the useful part only exists in the rear of the file, why?
Are you implying that GetSelText has returned you the rtf string?

Try using GetWindowText instead.

Dave
workaholic
2007-01-05 12:01:58 UTC
Permalink
Post by David Lowndes
Post by workaholic
I want my text written in CRichEditCtrl to output as plain text, and I
...
But it turns out to be a complex text with lengthy ugly characters and
the useful part only exists in the rear of the file, why?
Are you implying that GetSelText has returned you the rtf string?
Try using GetWindowText instead.
Dave
Well...it does reduce the last file's size from 16K to 4K, but it still
contains unknown characters, maybe I should not use CString?
David Lowndes
2007-01-05 12:44:39 UTC
Permalink
Post by workaholic
Post by David Lowndes
Post by workaholic
I want my text written in CRichEditCtrl to output as plain text, and I
...
But it turns out to be a complex text with lengthy ugly characters and
the useful part only exists in the rear of the file, why?
Are you implying that GetSelText has returned you the rtf string?
Try using GetWindowText instead.
Dave
Well...it does reduce the last file's size from 16K to 4K, but it still
contains unknown characters, maybe I should not use CString?
CString is not the problem here.

What are these unknown characters?

If you enter a very simple string "ABC" - what are the contents of the
CString variable after you call GetWindowText?

Dave
workaholic
2007-01-05 13:03:05 UTC
Permalink
Post by David Lowndes
Post by workaholic
Post by David Lowndes
Post by workaholic
I want my text written in CRichEditCtrl to output as plain text, and I
...
But it turns out to be a complex text with lengthy ugly characters and
the useful part only exists in the rear of the file, why?
Are you implying that GetSelText has returned you the rtf string?
Try using GetWindowText instead.
Dave
Well...it does reduce the last file's size from 16K to 4K, but it still
contains unknown characters, maybe I should not use CString?
CString is not the problem here.
What are these unknown characters?
If you enter a very simple string "ABC" - what are the contents of the
CString variable after you call GetWindowText?
Dave
These are my Serialize function, I add a AfxMessageBox(m_text), but the
dialog box proves the m_text is all right, I really where the problem is!
void CLispEditorDoc::Serialize(CArchive& ar)
{
POSITION pos = GetFirstViewPosition();
CRichEditView* pFirstView =(CRichEditView*) GetNextView( pos );

CRichEditCtrl *pCtrl = &pFirstView->GetRichEditCtrl();
pCtrl->GetWindowText(m_text);

if (ar.IsStoring())
{
ar<<m_text;// TODO: add storing code here
}
else
{
ar>>m_text;// TODO: add loading code here
}

// Calling the base class CRichEditDoc enables serialization
// of the container document's COleClientItem objects.
// TODO: set CRichEditDoc::m_bRTF = FALSE if you are serializing as text
CRichEditDoc::m_bRTF = FALSE;
CRichEditDoc::Serialize(ar);

}

thanks a lot!
David Lowndes
2007-01-05 14:12:17 UTC
Permalink
Post by workaholic
These are my Serialize function, I add a AfxMessageBox(m_text), but the
dialog box proves the m_text is all right, I really where the problem is!
void CLispEditorDoc::Serialize(CArchive& ar)
{
// Calling the base class CRichEditDoc enables serialization
// of the container document's COleClientItem objects.
// TODO: set CRichEditDoc::m_bRTF = FALSE if you are serializing as text
CRichEditDoc::m_bRTF = FALSE;
CRichEditDoc::Serialize(ar);
I've never used a rich edit control (or the MFC document wrapper)
myself, but that must be doing something extra - and if you don't need
if why not try removing it?

Dave
workaholic
2007-01-05 15:14:30 UTC
Permalink
Post by David Lowndes
Post by workaholic
These are my Serialize function, I add a AfxMessageBox(m_text), but the
dialog box proves the m_text is all right, I really where the problem is!
void CLispEditorDoc::Serialize(CArchive& ar)
{
// Calling the base class CRichEditDoc enables serialization
// of the container document's COleClientItem objects.
// TODO: set CRichEditDoc::m_bRTF = FALSE if you are serializing as text
CRichEditDoc::m_bRTF = FALSE;
CRichEditDoc::Serialize(ar);
I've never used a rich edit control (or the MFC document wrapper)
myself, but that must be doing something extra - and if you don't need
if why not try removing it?
Dave
Yeah, I have tried, but it seems that whether remove it or not doesn't
really matters,Thank you for attention!

Loading...