CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Help!

  1. #1
    Join Date
    Apr 1999
    Posts
    121

    Help!

    Can someone give me a hint on how I can save a path writen in a Edit box so That when the user closes the program and re-opens it that path is still in the edit box. What ever was last put into it?

    Thank you


  2. #2
    Join Date
    May 1999
    Location
    Toronto, Ontario, Canada
    Posts
    155

    Re: Help!

    At close Program do the following
    1) get the contents of the edit box by using SetWindowText (or through DDX)
    2) save the contents in the registry (or an INI file)

    At startup, do the following
    1) read the registry (or INI file) for the previous edit box content.
    2) use SetWindowText to setup the edit box (OnInitDialog), alternately, you can use DDX through the ClassWizard.

    -Safai


  3. #3
    Join Date
    Apr 1999
    Posts
    121

    Re: Help!

    Would you be able to point me to an example or would you have an example I could work from?

    Thank you in advance


  4. #4
    Join Date
    May 1999
    Location
    Toronto, Ontario, Canada
    Posts
    155

    Re: Help!

    I can't think of any examples right now. But this should be pretty straight forward.

    First, you handle OnDestroy of your dialog, insert ON_WM_DESTORY into the message map.


    void YourDialog::OnDestroy()
    {
    CWnd *pWnd = GetDlgItem(IDC_YOUREDITCONTROL);
    if (pWnd)
    {
    CString str;
    pWnd->GetWindowText(str);

    // this saves it into your INI file
    //+ToDo: use registry to store the string
    // there are plenty of examples on how to access the registry
    // on this site
    AfxGetApp()->WriteProfileString("Your Section", "Your Item", str);
    }

    CDialog::OnDestroy();
    }




    And then read in that string OnInitDialog


    int YourDialog::OnInitDialog()
    {
    CDialog::OnInitDialog();

    // if the string is not present in the INI file,
    // it will return the default string
    CString str = AfxGetApp()->GetProfileString("Your Section", "Your Item", "Your edit box default");

    CWnd *pWnd = GetDlgItem(IDC_YOUREDITCONTROL);
    if (pWnd)
    {
    pWnd->SetWindowText(str);
    }

    return TRUE;
    }




    -Safai

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