CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Feb 2004
    Posts
    38

    Dialog Boxes (Urgent)

    Does anyone know what has to be done to save the informations entered in a dialog box to a file and to retrieve it when needed?

    The application is a SDI and the dialog box is called from the menu.

  2. #2
    Join Date
    Sep 2003
    Posts
    90
    You have to store the values that are accepted from the
    controls in the dialog box and write that values into file.



    then whenever the dialogbox pops up...in Initdialog function you read the file and update the individual values.

    The format of the file should be decided by you only...where to write a specific contol value in a file.

  3. #3
    Join Date
    Sep 2002
    Posts
    924
    Lookup WritePrivateProfileString and GetPrivateProfileString in MSDN, or search the forum. You could also search for information on using .INI files. You should find what you are looking for fairly quickly.

  4. #4
    Join Date
    Feb 2004
    Posts
    38
    The situation here is I have a SDI application and a dll file.

    When I run the a menu from the application, a dialog box will popup and I would like to be able to write the inputs to a file and to be able to open the file when i need it.

    Is it possible ?

    If so can you tell me the way to do it in steps.

    1 more point to note is that the dialog box is created in the application and the functions will be called from the dll.

  5. #5
    Join Date
    Feb 2002
    Posts
    3,788

    Re: Dialog Boxes (Urgent)

    Originally posted by Kel
    Does anyone know what has to be done to save the informations entered in a dialog box to a file and to retrieve it when needed?

    The application is a SDI and the dialog box is called from the menu.
    see attached. just press File->New and see the rest.
    Attached Files Attached Files

  6. #6
    Join Date
    Sep 2002
    Posts
    924
    Although I have not looked at the code myth7676 attached here (maybe your answer is there), if you want a specific answer you need to be tad more specific about want you want.

    For example:
    Is this dialog box something that you use to save settings?
    i.e. You only need to save the most recent data from the dialog box and you also need to read this information back into the dialog box's controls everytime the dialog box is shown. In this type of situation .INI files, or using the registry is good.

    Or, is this something where you want the information in the dialog box, appended to a file, so that you save every entry ever made (unless of course you edit the file yourself), and you do not need to read the file from within the program?

    Either way it is possible to do what you want, but you would use different methods depending on exactly what your needs are.

    Also, are you using member variables for you controls on your dialog box? (and what types of controls).

    If you are looking for specific steps, then this info will help you to get a more relevant answer.

  7. #7
    Join Date
    Feb 2002
    Posts
    3,788
    if you want to have mutltiple sets of data, you should do the following when you try to write to the file:
    Code:
    void CNewDlg::OnOK() 
    {
    	// TODO: Add extra validation here
    	
    	CFileException e;
    	char* pFileName = "test.dat";
    	
    	if( !m_File.Open( pFileName, CFile::modeCreate | CFile::modeNoTruncate| CFile::modeWrite, &e ) )
    	{
    #ifdef _DEBUG
    		afxDump << "File could not be opened " << e.m_cause << "\n";
    #endif
    	}
    	else
    	{
    		UpdateData();
    		
    		m_File.SeekToEnd();
    		m_File.WriteString("EDIT1: " + m_strEdit1 + "\n");
    		m_File.WriteString("EDIT2: " + m_strEdit2 + "\n");
    		m_File.Close();	
    						
    	}
    	
    	CDialog::OnOK();		
    }

  8. #8
    Join Date
    Feb 2004
    Posts
    38
    Let's say its something like a username and password storage file.

    When running the program for the first time, there's no file being created and when I enter 1 set of information and save it, the file will be created and the information will be stored in the file and when I enter the next set of information, the datas will be added into the file.

    I would also like to be able to retrieve the set of information I've entered either by searching base on name or by browsing all the records (either method will do)

    I hope you get what I meant

  9. #9
    Join Date
    Feb 2004
    Posts
    38
    ok. now that i can write multiple datas, i would like to know how can i retrieve the specific set of datas?

    eg.

    #1
    EDIT1: 222 333
    EDIT2: 333 444

    #2
    EDIT1: 111
    EDIT2: 333 444

    there's two sets of records and let's say i will be retriving the set of data based on the values in EDIT1

    eg. I would like to retrieve record 1 which is EDIT1: 222 333
    and it will show be both datas for EDIT1 and EDIT2

    how should i write the code to search through the file?

  10. #10
    Join Date
    Sep 2002
    Posts
    924
    One possibilty would be to make the entries comma delimeted,
    i.e.
    EDIT1: 222 333
    EDIT2: 333 444

    EDIR1: 555 666
    EDIT2: 777 888

    stored in file like this:
    222 333,333 444
    555 666,777 888

    and then read the file line by line, storing the values in variables and comparing those values to the value you are looking for, stopping when you founnd the value you are looking for, etc

    An example of reading a comma delimited file and extracting the strings can be found here:
    http://www.codeproject.com/file/importstringvalues.asp

    That should give you an idea of how to do what you want.

  11. #11
    Join Date
    Feb 2004
    Posts
    38
    Thanks RussG1 and myth7676

    that's just what I needed.

    by the way do your know the code for closing an application ?

    eg. When I first run the application, it will popup a dialog box and if the input is not what I wanted I would like to shut down the application.

    Is there any codings avaliable for it?

  12. #12
    Join Date
    Sep 2002
    Posts
    924
    I assume by your description, that this is a Dialog app, in which case, you could exit your application using EndDialog.

  13. #13
    Join Date
    Feb 2004
    Posts
    38
    Mine is a SDI application.

    btw RUSS I pm you. Not sure if you received it.

  14. #14
    Join Date
    Sep 2002
    Posts
    924
    I am not sure what is the best way for SDI, but I think you can use OnAppExit() to exit the SDI app. I will check my PM.

  15. #15
    Join Date
    Feb 2004
    Posts
    38
    Thanks for the suggestion.

    I'll try that later.

    Got some problems with retrieving the datas from file.

    BTW Russ I pm u not sure if u read it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured