| |

VerySource

 Forgot password?
 Register
Search
View: 775|Reply: 4

CRichEditCtrl serialization issue

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-22 17:00:01
| Show all posts |Read mode
I use CRichEditView to write a text editor, store the characters in CString, and want to write it into a plain text. But after doing the following, the resulting file always has a complicated garbled beginning. What should I do?
void CLispEditorDoc :: Serialize (CArchive&ar)
{
POSITION pos = GetFirstViewPosition ();
CRichEditView * pFirstView = (CRichEditView *) GetNextView (pos);

CRichEditCtrl * pCtrl =&pFirstView-> GetRichEditCtrl ();
pCtrl-> GetWindowText (m_text);
// AfxMessageBox (m_text);
Ranch
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);

}
Reply

Use magic Report

0

Threads

3

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-7-29 13:00:01
| Show all posts
First of all, your code is not safe and the pointers are not judged
Is m_text initialized
Is it the correct result for you to pop up the MessageBox
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-8-1 21:30:01
| Show all posts
m_text is a member I defined in the Document class, there should be no problem. Does CRichEditDoc::Serialize(ar) output a file with a file header?
Later I changed the code to:
void CLispEditorDoc::Serialize(CArchive&ar)
{


if (ar.IsStoring())
{

}
else
{

}

// 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);

}

The effect is almost the same as last time, speechless.
If you delete the Serialize function in ClassWizard, can you override OnCloseDocument and OnOpenDocument by yourself?
Reply

Use magic Report

0

Threads

10

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 Spain

Post time: 2020-8-1 22:45:01
| Show all posts
Go and see how CString is serialized
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-8-3 12:00:01
| Show all posts
Where can I see it?
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list