Click to See Complete Forum and Search --> : Help!


Sophie
May 7th, 1999, 08:28 AM
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

Safai Ma
May 7th, 1999, 09:03 AM
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

Sophie
May 7th, 1999, 09:52 AM
Would you be able to point me to an example or would you have an example I could work from?

Thank you in advance

Safai Ma
May 7th, 1999, 10:08 AM
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