-
OK I am kind of new at VC++ and really new to MFC programs.
I have a MFC FormView program that has just an Edit Box on a form. What I want to do is save the text from the Edit Box to a file also write the text from a text file to the edit box.
In my View Object I have DoData Exchange that saves the text to a VAR called editTextOut.
Code:
void CTestMFCFrmViewDoc::Serialize(CArchive& ar)
{
CString F = "";
//#1 CTestFrmViewView* pView = (CTestFrmViewView*)m_viewList.GetHead();
//#2 ASSERT_KINDOF(CTestFrmViewView, pView);
if (ar.IsStoring())
{
pView->UpdateData();
F = pView->editTextOut;
ar << F;
}
else
{
ar >> F;
pView->RedrawWindow(NULL,NULL, RDW_ERASENOW);
}
}
Question 1: Is using //#1 & //#2 the correct way to point pView to the CTestFrmViewView object? I got this from an example somewhere else, but it just seems like the wrong way to do it.
Question 2: After I read in the text from a text file how do I send the edit box?
Thanks
-
If you like you can use this code to open a file.
Code:
#include <string>
#include <fstream>
using namespace std;
string got,all;
ifstream in(filename);
while(getline(in,got))
{
all += got + "\r\n";
}
edit = all.c_str();
UpdateData(FALSE);
Answer 2:
Code:
edit = varcontainingtext;
UpdateData(FALSE);
-
Ahh Thanks Vlatko but I already can read from a file thats what ar >> F; does.
I wanted to be sure that the code I am using is the correct way of doing it.
Incase someone else reads this here is how to put the text to the edit box using my code.
Code:
pView->editTextOut = F;
pView->UpdateData(false);
Thanks for the help Vlatko