EDIT Box to load up a .TXT File

Ok I have asked this before in the past, but I'm slow to this MFC Visual C++ stuff. I don't know any of the terms, all I do know is that I'm using MS Visual C++ 6.0, and how to point and click and type in stuff and semi, know how to program in VC a little.

Anyway, if you are going to give me cut and past code from codeguru.com then please explain it to me simply where it needs to go.

I have my Dialog box, in the call CMyDialog, in the box I have a Edit box, I have a veriable assisnged to it, called m_Message. I want the edit box to load up a txt file (yes it will be less then 64K) into the edit box when the program is loaded. It's just a one window dialog box program. Where do I put this code once I do get it? If you are familr with MS' Visual C++ Program, if you could tell me where exactly to go.  Thanks very much.
LVL 2
fredmastroAsked:
Who is Participating?
 
Vinayak KumbarConnect With a Mentor Sr Program ManagerCommented:
Hi,

I assume that the variable m_Message is of CString class. In  the OnInitDialog() of the dialog. U can load the file and then display it.

These will bethe steps in OnInitDialog()

1. Open the text file using CFile
CFile file;
if(file.Open("d:\\myfile.txt", CFile::modeRead))
{
char *chTemp = NULL;
int len = file.GetLength();
chTemp = new char[len + 1];
ZeroMemory(chTemp, len + 1);

file.Read(chTemp, len);
m_Message = chTemp;

if(chTemp)
{
delete chTemp;
chTemp = NULL;
}
}
0
 
SadhuCommented:
In OnInitDialog() function of your CMyDialog class. If you do not have function from menu->Class-wizard->select MyDialog class->add functon for WM_INITDIALOG. read text file into buffer then copy to m_Message and then call UpdateData(FALSE).

Hope this helps
Sadhu
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

I forgot to tell. put this code before the OnInitDialog()'s
return TRUE;

UpdateData(FALSE);
So that it will update the edit box.

Hope this helps. If U want sample I will send it to U. give me Ur mailID.

VinExpert
0
All Courses

From novice to tech pro — start learning today.