Beginner needs a little help

GregLuke used Ask the Experts™
Well, maybe a bit more than a little.

Actually, I am looking for a tutorial on putting together a simple program.  Something like enterring your name, address and phone number and then write it out to a file.  The tutorials with the Learn MFC package don't offer anything like this.  I have gotten the dialog boxes all set up but really don't know how to get the info from the dialog boxes, to a structure or class and then written to a file.


Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

if you want to get data from the dialog boxes first create variables for the respected controls. After entering data into the controls you use below statement
  "UpdateData(TRUE);" now the values in controls comes into corresponding control variables then take that values and open a file using serialization concept.
Best of Luck.
with friendly

to elaborate on vgkotha's answer

 Using CTRL-W bring up the class wizard
 hit the 'member variables' tab
 you will see your controls listed
 double click on each
 You will get the Add member Variable Dialog
 Enter a name i.e. m_editAddress, m_editName
 The Category is 'Control'
 The Variable Type is 'CEdit'
 Click the Message Maps Tab
 In the Object ID's listbox scroll down to IDOK
 In the 'Messages' Listbox Double click BN_CLICKED

 You will be in Code

 Use this code to write to a file

 CStdioFile file;
 file.Open ( "MyFile.Txt", CFile::modeWrite | CFile::modeCreate );

 CString csData;
 m_editAddress.GetWindowText ( csData );
 file.WriteString ( csData );
 m_editName.GetWindowText ( csData );
 file.WriteString ( csData );

 etc etc

 file.Close ();

 Run your Dialog
 Enter Some data
 Press OK

 In your debug folder there will be a file called MyFile.Txt



Thanks very much, I will give that a shot.


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial